Link to home
Start Free TrialLog in
Avatar of heuer
heuer

asked on

return value of a dialog box.

// Defines what event takes place when button is clicked
public void actionPerformed(ActionEvent e)
{

  if(name.equals("Quit"))
  {
   //Show an information panel with the options yes/no and message 'choose one':
   JOptionPane.showConfirmDialog(null,"Are you sure of that?", "RE-CONFIRM", JOptionPane.YES_NO_OPTION);
  }

}

From the above codes, how can I capture which button did the user clicked on. If he clicks on Yes then the program will end but when he clicks on No, the program will continue.
ASKER CERTIFIED SOLUTION
Avatar of mattyk
mattyk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of heuer
heuer

ASKER

Perfect. Thanks a lot mattyk.
Avatar of heuer

ASKER

What about this new set of codes?

newboy.setName(JOptionPane.showInputDialog("Please enter name of boy:") );

The above codes will produce a dialog box that prompts user for a name. 2 buttons will be provided for the user i.e. 'OK' and 'CANCEL'. My program will even display the boy when the user clicks on Cancel. This shouldn't be the case. The boy should only be displayed after the user adds his name and clicks on 'OK'.

How can I do a check here like the previous question. If the user clicks on Cancel then the boy will not be added to the screen.