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 09 Nov 2009
 */
public class UserAgePopUps {

  public static void main(String[] args) {

    //returns whatever user typed
    String input = JOptionPane.showInputDialog("Enter your year of birth:");
    if (input == null) {
      //user cancelled or closed window, so end program
      return;
    }

    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) {
      JOptionPane.showMessageDialog(null, "You must enter a number " +
        "as your year of birth.  Please try running the program again.");
    }
  }

}
