Java JOptionPane get user input

Description

Java JOptionPane get user input

import javax.swing.JOptionPane; 

public class Main 
{
   public static void main(String[] args)
   {//from   ww  w  .j a v  a2 s . c  o  m
      String firstNumber = 
         JOptionPane.showInputDialog("Enter first integer");
      String secondNumber =
          JOptionPane.showInputDialog("Enter second integer");

      int number1 = Integer.parseInt(firstNumber); 
      int number2 = Integer.parseInt(secondNumber);

      int sum = number1 + number2;

      JOptionPane.showMessageDialog(null, "The sum is " + sum, 
         "Sum of Two Integers", JOptionPane.PLAIN_MESSAGE);
   } 
} 



PreviousNext

Related