Source of ExerciseJOptionPane.java


  1: 
  2: 
  3: import javax.swing.*;
  4: 
  5: public class ExerciseJOptionPane
  6: {
  7:    public static void main(String[] args)
  8:    {
  9:       boolean adult = false;
 10:       //Initialized to keep the compiler happy.
 11: 
 12:       int answer =
 13:          JOptionPane.showConfirmDialog(null,
 14:                 "Are you 18 years old or older?",
 15:                 "Age Check", JOptionPane.YES_NO_OPTION);
 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(
 25:                         null, "You are old enough.");
 26:       else
 27:           JOptionPane.showMessageDialog(
 28:                         null, "Sorry. you must be 18.");
 29:       System.exit(0);
 30:    }
 31: }