// DialogIo.java

// Does simple string I/O using dialog boxes

import javax.swing.JOptionPane;

public class DialogIo
{
   public static void main(String[] args)
   {
      String response;		// declare a variable to hold user's reply

      // show how to get strings in and out of dialog boxes
      response = JOptionPane.showInputDialog("What's your name?");
      JOptionPane.showMessageDialog(null, "Nice to meet you " + response);

      // show how to convert string input into numbers
      response = JOptionPane.showInputDialog("Enter an integer:");
      int num1 = Integer.parseInt(response);
      response = JOptionPane.showInputDialog("Enter another integer:");
      int num2 = Integer.parseInt(response);
      JOptionPane.showMessageDialog(null, "The sum of " + num1 + " plus " + num2
                                          + " equals " + (num1 + num2) );
      // let's do this again with real numbers
      response = JOptionPane.showInputDialog("Enter a real number:");
      double num3 = Double.parseDouble(response);
      response = JOptionPane.showInputDialog("Enter another real number:");
      double num4 = Double.parseDouble(response);
      JOptionPane.showMessageDialog(null, "The sum of " + num3 + " plus " + num4
                                          + " equals " + (num3 + num4) );
      System.exit(0);
   }
}