import javax.swing.JOptionPane; public class InputExample { public InputExample() { String name = JOptionPane.showInputDialog( null, "Please enter your name: "); int age = Integer.parseInt( JOptionPane.showInputDialog( null, "Please enter your age: ")); JOptionPane.showMessageDialog(null, "Hello " + name + ". You are " + age + " years old!"); // BOOLEAN EXAMPLE int selection = JOptionPane.showConfirmDialog( null , "Should we do something" , "Selection : " , JOptionPane.OK_CANCEL_OPTION , JOptionPane.INFORMATION_MESSAGE); System.out.println("I be written" + " after you close, the JOptionPane"); if (selection == JOptionPane.OK_OPTION) { // Code to use when OK is PRESSED. System.out.println("Selected Option is OK : " + selection); } else if (selection == JOptionPane.CANCEL_OPTION) { // Code to use when CANCEL is PRESSED. System.out.println("Selected Option Is CANCEL : " + selection); } } }