Source of JOptionPaneDemo.java


  1: //JOptionPaneDemo.java
  2: //Illustrates the use of a JOptionPane for input.
  3: 
  4: import javax.swing.JOptionPane;
  5: 
  6: public class JOptionPaneDemo
  7: {
  8:     public static void main(String[] args)
  9:     {
 10:         String appleString =
 11:             JOptionPane.showInputDialog("Enter number of apples:");
 12:         int appleCount = Integer.parseInt(appleString);
 13: 
 14:         String orangeString =
 15:             JOptionPane.showInputDialog("Enter number of oranges:");
 16:         int orangeCount = Integer.parseInt(orangeString);
 17: 
 18:         int totalFruitCount = appleCount + orangeCount;
 19:         JOptionPane.showMessageDialog(null,
 20:             "The total number of fruits = " + totalFruitCount);
 21:         System.exit(0);
 22:     }
 23: }