showInputDialog()
Show a message and get one line of user input. The input dialog has an additional component for user input. This can be a text field into which the user can type an arbitrary string.
Get the integer value from showInputDialog using Integer.parseInt().
Program
Program Source
import javax.swing.JOptionPane; public class Javaapp { public static void main(String[] args) { String value = JOptionPane.showInputDialog("Enter value1","value1"); int totel = Integer.parseInt(value); value = JOptionPane.showInputDialog("Enter value1","value1"); totel += Integer.parseInt(value); JOptionPane.showMessageDialog(null,"Totel value is " + totel); } }
Very nice article, exactly what I needed.