import javax.swing.JOptionPane; // include GUI class called "JOptionPane" import java.util.Scanner; /** Let's make a very simple Graphical User Interface -- pop up windows * that do input and output. Let's multiply 2 numbers. * For more information on JOptionPane, go to the API Web site * java.sun.com/j2se/1.5.0/docs/api, and scroll down to the JOptionPane link. */ public class TinyGUI { public static void main(String [] args) { // Get input string from a pop-up window String input = JOptionPane.showInputDialog("Enter 2 numbers separated by a space"); // Parse the string with StringTokenizer to get the 2 numbers Scanner inputScanner = new Scanner(input); int first = inputScanner.nextInt(); int second = inputScanner.nextInt(); // Now we're ready to multiply and give result. // It turns out that the showMessageDialog() function requires 2 parameters: // 1. the name of a frame (in this case there isn't one so we say "null") // 2. a String to print String answer = "The product of " + first + " and " + second + " is " + (first * second) + "."; JOptionPane.showMessageDialog(null, answer); } }