It might help if you added brackets to the first if statement. (In red)
Action listener -
if(event.getSource() == cmdSaveSettings) {
if(txtPlayerOneName.getText().equals(emptyText))
{
JOptionPane.showMessageDialog(null, "alert", "Please enter player one's name", JOptionPane.ERROR_MESSAGE);
}
}
jasimp
Senior Poster
3,623 posts since Aug 2007
Reputation Points: 533
Solved Threads: 53
I would put in some code at the top of the actionPerformed function that displays a message saying the program is inside actionPerformed. Or you can add a breakpoint and do the same thing. If it doesn't get inside the actionPerformed function, then the problem is not there. If it does, put some code to display that the event source is indeed cmdSaveSettings. If it isn't, again the problem is probably outside of actionPerformed. Then narrow it down some more to see if it gets in the code belonging to this if statement:
if(txtPlayerOneName.getText().equals(emptyText))
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Something like this:
public void actionPerformed(ActionEvent event)
{
System.out.println ("In actionPerformed");
if(event.getSource() == cmdSaveSettings)
{
System.out.println ("Source is cmdSaveSettings");
if(txtPlayerOneName.getText().equals(emptyText))
{
System.out.println ("Inside if statement");
JOptionPane.showMessageDialog(null, "alert", "Please enter player one's name",
JOptionPane.ERROR_MESSAGE);
}
}
}
Depending on which, if any, of these statements display as output when you press the button, you have a better handle on what is happening and what the problem is.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Well, equals compares the String values (the String equals method that is, of course) of the referenced Objects. The String value of the null reference is "null" not "". Keep that in mind. ;-)
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494