import javax.swing.JOptionPane;

/**
 * A brief example of using JOptionPanes as the basis for a primitive GUI.
 * This program just asks the user for their year of birth and outputs
 * their age.
 *
 * @author Zach Tomaszewski
 * @version 02 Apr 2009
 */
public class UserAgePopUps {

  public static void main(String[] args) {

    //returns whatever user typed, or null if they closed or canceled window
    String input = JOptionPane.showInputDialog("Enter your year of birth:");

    try{
      String output = "Your age is: " + (2009 - Integer.parseInt(input));

      //displays output String; null is the "parent window" of the popup
      JOptionPane.showMessageDialog(null, output);

    }catch (NumberFormatException nfe) {
      if (input == null) {
        //do nothing, since user closed the input window
      }else {
        JOptionPane.showMessageDialog(null, "You must enter a number " +
          "as your year of birth.  Please try running the program again.");
      }
    }
  }

}
