Obtaining user input from a Swing dialog. - Java Swing

Java examples for Swing:JOptionPane

Description

Obtaining user input from a Swing dialog.

Demo Code

import javax.swing.JOptionPane;

public class Main
{
   public static void main(String[] args)
   {//  ww  w  . j  a v a 2  s  .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);
   } 
}

Related Tutorials