I need to check whether a text field (ID) has anything other than a numerical value. I am parsing the string in the text field to a int. I tried catching the error with a try-catch block, but every time the field has anything other than an int, it displays an error messages and terminates the whole program. I want the user to be able to go back and edit the ID field.
try{
int id = Integer.parseInt(fieldID.getText());
}
catch(NumberFormatException e2){
JOptionPane.showMessageDialog(null, "Please enter a valid ID","Alert!", JOptionPane.ERROR_MESSAGE);
}