You have a semicolon at the end of the first line. Thus, this is not very well tested.
A statement like this (what you have):
if (condition) ;
will execute an empty statement (;) if the condition is true, and then go to the next line. If the condition is false, it simply moves on to the next line. These two actions have the same result.
You can try using curly braces for all if statements. Sometimes it is tiring, but complicates corruption.
if (!(Pattern.matches("^[a-zA-Z]+$", answerField1.getText()))) { JOptionPane.showMessageDialog(null, "Please enter a valid character", "Error", JOptionPane.ERROR_MESSAGE); }
What would i do. You can just delete the semicolon.
source share