Source of Question23.java


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