//Dialog.java //demo of JOptionPane input and output dialog windows import javax.swing.*; //for JOptionPane public class Dialog { //extends JApplet { //public void init () { public static void main (String[] argv) { String name, input; int age; double radius, circumference, area; //showInputDialog returns a String, //assign it to a String variable (object): name = JOptionPane.showInputDialog( "Enter your name please" ); //showMessageDialog displays a string JOptionPane.showMessageDialog( null, "Welcome: " + name ); //null must be the first argument //2nd argument is string, here with string concatenation input = JOptionPane.showInputDialog( "Enter your age in years" ); //to input an int, need to convert String to int: age = Integer.parseInt( input ); //extremely finicky age++; JOptionPane.showMessageDialog( null, "On your next birthday you will be: " + age ); input = JOptionPane.showInputDialog( "Enter radius of a circle" ); //to input a double, need to convert String to double: radius = Double.parseDouble( input ); circumference = 2 * radius * Math.PI; area = radius*radius * Math.PI; JOptionPane.showMessageDialog( null, "Circumference=" + circumference + " Area=" + area); } }