I'm trying to show a dialog message if the user clicks a button and a text field is empty.
Action listener -
if(event.getSource() == cmdSaveSettings)
if(txtPlayerOneName.getText().equals(emptyText))
{
JOptionPane.showMessageDialog(null, "alert", "Please enter player one's name", JOptionPane.ERROR_MESSAGE);
}
Ive add an action to listener to the button and the textfield:
(mouse listener also as removes original text on click which works fine)
cmdSaveSettings = new JButton("Save Settings");
this.cmdSaveSettings.addActionListener(this);
txtPlayerOneName = new TextField("Player One", 15);
this.txtPlayerOneName.addMouseListener(this);
this.txtPlayerOneName.addActionListener(this);