Posted on 2004-10-18
I have a JTextField and an enter button. The user will enter a number into the JTextfield and hit enter when he is done.
What is the best way to read and write to a JTextField box. I want to limit the input field to numbers
between 1 -100. The problem I have is if the field is empty whent the enter button is pushed I receive an exception.
Here is my code:
oHOTValue = heightOfTargetTextField.getText();
catch (NumberFormatException s )
oHOTValue = "1";
String sHOTValue = oHOTValue.toString();
int iHOTValue = Integer.parseInt(sHOTValue);
zoomConfig.setTargetHeight( iHOTValue );
iHOTValue = zoomConfig.getTargetHeight();
String sValue = Integer.toString(iHOTValue);
System.out.println("HOT button pressed : " + iHOTValue);
The try catch is not working correctly.