Reference from Java Notes: JOptionPane
– Simple Dialogs
JOptionPaneTest1.java
// File: joptionpane-examples/JOptionPaneTest1.java // Description: JOptionPane example. // Author: Fred Swartz // Date: 31 Jan 2005 import javax.swing.JOptionPane; public class JOptionPaneTest1 { public static void main(String[] args) { String ans; ans = JOptionPane.showInputDialog(null, "Speed in miles per hour?"); if (ans==null) System.exit(0); try { double mph = Double.parseDouble(ans); double kph = 1.621 * mph; JOptionPane.showMessageDialog(null, "KPH = " + kph); } catch (NumberFormatException e) { System.out.println("Please enter a valid number"); } System.exit(0); } }
Maintained by John Loomis, updated Thu Sep 05 11:37:20 2013