public class Question23
1: //Question23.java
2: //Solution to Self-Test Question 23, page 168, Chapter 23.
3:
4: import javax.swing.JOptionPane;
5:
6: public class Question23
7: {
8: public static void main(String[] args)
9: {
10: boolean adult = false;
11: //Initialized to keep the compiler happy.
12:
13: int answer = JOptionPane.showConfirmDialog(null,
14: "Are you 18 years old or older?",
15: "Age Check", JOptionPane.YES_NO_OPTION);
16:
17: if (answer == JOptionPane.YES_OPTION)
18: adult = true;
19: else if (answer == JOptionPane.NO_OPTION)
20: adult = false;
21: else
22: System.out.println("Error");
23:
24: if (adult)
25: JOptionPane.showMessageDialog(null, "You are old enough.");
26: else
27: JOptionPane.showMessageDialog(null, "Sorry. you must be 18.");
28: System.exit(0);
29: }
30: }