Showing a Dialog Box

// Modal dialog with OK button. JOptionPane.showMessageDialog(frame, "Line1\nLine2"); // Modal dialog with yes/no button. int answer = JOptionPane.showConfirmDialog(frame, "Line1\nLine2"); if (answer == JOptionPane.YES_OPTION) { // User clicked YES. } else if (answer == JOptionPane.NO_OPTION) { // User clicked NO. } // Modal dialog with OK/cancel and a text field String text = JOptionPane.showInputDialog(frame, "Line1\nLine2"); if (text == null) { // User clicked cancel } else { process(text); }

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.