Greet3.java

Download Greet3.java

 1: /* A simple program to display a friendly greeting.  This stand-alone
 2:  * Java program demonstrates keyboard input using a simple GUI method.
 3:  * The use of a GUI input method in an otherwise non-gui program is okay
 4:  * in the classroom but probably not otherwise.
 5:  * The dialogs of JOptionPane can be customized with special icons, titles,
 6:  * and different buttons.  See the Java docs for details.
 7:  *
 8:  * Written by Wayne Pollock, Tampa, FL USA, 2002.  Updated 2005 for Java5.
 9:  * Updated in 2010 to show message dialogs instead of console output.
10:  */
11: 
12: import javax.swing.JOptionPane;
13: 
14: class Greet3
15: {
16: 
17:    public static void main ( String [] args )
18:    {
19:       String name = JOptionPane.showInputDialog( "Please enter your name: " );
20: 
21:       // null is returned when the user clicks cancel:
22:       if ( name != null )
23:          JOptionPane.showMessageDialog( null, "Hello " + name + "!" );
24: 
25:       // Here's an example that changes the title and the type too:
26:       JOptionPane.showMessageDialog( null, "End of Program",
27:          "Greet3 Dialog", JOptionPane.PLAIN_MESSAGE );
28: 
29:    }  // End of main
30: }  // End of class Greet3