//InputDialog.java //demo of input (and output) with JOptionPane windows import javax.swing.*; //needed for JOptionPane public class InputDialog { public static void main (String [] args) { String name, input; int age; double radius, circumference, area; //JOptionPane input dialog window. //showInputDialog method has prompt string parameter, // returns a String, assign it to a string variable: 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 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! //parameter to parseInt is a string. //returns an int value, assign it to int variable. age = age + 1; JOptionPane.showMessageDialog( null, "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 ); //very finicky! //parameter to parseDouble is a string. //returns a double value, assign it to double variable. circumference = 2 * Math.PI * radius; area = Math.PI * radius*radius; JOptionPane.showMessageDialog( null, "Circumference=" + circumference + "\nArea=" + area); } }