O'Reilly logo

Java™ How To Program (Early Objects), Tenth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Entering Text in a Dialog

Figure 3.13 uses another predefined JOptionPane dialog called an input dialog that allows the user to enter data into a program. The program asks for the user’s name and responds with a message dialog containing a greeting and the name that the user entered.

 1   // Fig. 3.13: NameDialog.java 2   // Obtaining user input from a dialog. 3   import javax.swing.JOptionPane; 4  5   public class NameDialog 6   { 7      public static void main(String[] args) 8      { 9         // prompt user to enter name                                    10         String name = JOptionPane.showInputDialog("What is your name?");11 12         // create the message                                         13          ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required