Java JOptionPane show input dialog

Description

Java JOptionPane show input dialog


// Obtaining user input from a dialog.
import javax.swing.JOptionPane;

public class Main
{
   public static void main(String[] args)
   {/*w  w  w. j  a  va 2s.c  o  m*/
      // prompt user to enter name
      String name = JOptionPane.showInputDialog("What is your name?");
      
      // create the message
      String message =                                              
         String.format("Welcome, %s, to Java Programming!", name);

      // display the message to welcome the user by name 
      JOptionPane.showMessageDialog(null, message);
   } 
}



PreviousNext

Related