I have two text fields and they must add up to 100 when submit is clicked, if I put in correct values into text field there's no error but if I leave the text field blank or put a letter in it the error handling isn't right. Any ideas?
submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (validation == true) {
int numA = Integer.parseInt(aTextField.getText());
int numB = Integer.parseInt(aTextField.getText());
int sum = numA + numB;
if (sum == 100) {
validation = true;
System.out.println("success");
} else {
JOptionPane.showMessageDialog(createFrame, "A and B must add up to 100");
validation = false;
}
}
this is the error
int numA = Integer.parseInt(aTextField.getText());