public class JOptionPaneYesNoDemo
1: //JOptionPaneYesNoDemo.java
2: //Illustrates the use of a JOptionPane to get a Yes or No answer
3: //from the user.
4:
5: import javax.swing.JOptionPane;
6:
7: public class JOptionPaneYesNoDemo
8: {
9: public static void main(String[] args)
10: {
11: int answer = JOptionPane.showConfirmDialog(null, "End program?",
12: "Click Yes or No:", JOptionPane.YES_NO_OPTION);
13:
14: if (answer == JOptionPane.YES_OPTION)
15: System.exit(0);
16: else if (answer == JOptionPane.NO_OPTION)
17: System.out.println("One more time");
18: else
19: System.out.println("This is impossible");
20:
21: System.exit(0);
22: }
23: }