Java examples for Swing:JOptionPane
Addition program that uses JOptionPane for input and output.
import javax.swing.JOptionPane; public class Main { public static void main(String[] args) {/*w ww .jav a 2 s . c o m*/ // obtain user input from JOptionPane input dialogs String firstNumber = JOptionPane.showInputDialog("Enter first integer"); String secondNumber = JOptionPane.showInputDialog("Enter second integer"); // convert String inputs to int values for use in a calculation int number1 = Integer.parseInt(firstNumber); int number2 = Integer.parseInt(secondNumber); int sum = number1 + number2; // add numbers // display result in a JOptionPane message dialog JOptionPane.showMessageDialog(null, "The sum is " + sum, "Sum of Two Integers", JOptionPane.PLAIN_MESSAGE); } }