private JTextField getGunCoolingRateTextField() { if (gunCoolingRateTextField == null) { gunCoolingRateTextField = new JTextField(5); gunCoolingRateTextField.setText("" + battleProperties.getGunCoolingRate()); gunCoolingRateTextField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { boolean isValid = false; String text = ((JTextField) input).getText(); if (text != null && text.matches("\\d*(\\.\\d+)?")) { double gunCoolingRate = Double.parseDouble(text); isValid = (gunCoolingRate > 0 && gunCoolingRate <= 0.7); } if (!isValid) { WindowUtil.messageError( "'Gun Cooling Rate' must be a floating point number > 0 and <= 0.7.\n" + "Default value is 0.1."); gunCoolingRateTextField.setText("" + battleProperties.getGunCoolingRate()); } return isValid; } }); } return gunCoolingRateTextField; }
private JTextField getSentryBorderSizeTextField() { if (sentryBorderSizeTextField == null) { sentryBorderSizeTextField = new JTextField(5); sentryBorderSizeTextField.setText("" + battleProperties.getSentryBorderSize()); sentryBorderSizeTextField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { boolean isValid = false; String text = ((JTextField) input).getText(); if (text != null && text.matches("\\d+")) { int borderSize = Integer.parseInt(text); isValid = (borderSize >= 50); } if (!isValid) { WindowUtil.messageError( "'Sentry Border Size' must be an integer value >= 50.\n" + "Default value is 100."); sentryBorderSizeTextField.setText("" + battleProperties.getInactivityTime()); } return isValid; } }); } return sentryBorderSizeTextField; }
private JTextField getNumberOfRoundsTextField() { if (numberOfRoundsTextField == null) { numberOfRoundsTextField = new JTextField(5); numberOfRoundsTextField.setText("" + battleProperties.getNumRounds()); numberOfRoundsTextField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { boolean isValid = false; String text = ((JTextField) input).getText(); if (text != null && text.matches("\\d+")) { int numRounds = Integer.parseInt(text); isValid = (numRounds > 0); } if (!isValid) { WindowUtil.messageError( "'Number of Rounds' must be an integer value > 0.\n" + "Default value is 10."); numberOfRoundsTextField.setText("" + battleProperties.getNumRounds()); } return isValid; } }); } return numberOfRoundsTextField; }