I have a GUI design that has a number of fields that the user enters. I'm using a try-catch to deal with the exceptions that the user incorrectly enters. I was successful when the user enters a String into a number field (My id field) but I'm frustrated here trying to use an exception to handle when a user enters an integer into a text/String field.
Here is my code to give you an idea of what I did for the exception i did successfully. Thank you.
try {
String taskID = txtId.getText();
int id = Integer.parseInt(taskID);
String taskName = txtName.getText();
String taskDesc = txtDesc.getText();
boolean isCompleted = chkComp.isSelected();
int taskPriority = comboPriority.getSelectedIndex();
Task newTask = new Task(id, taskName, taskDesc, isCompleted, taskPriority);
tasks.add(newTask);
taskMod.addElement(newTask);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Error: You must enter an integer");
}