GUIGreet.java

Download GUIGreet.java

 1: // A stand-alone GUI Java program to display a friendly greeting.
 2: // Also added code to close the application when the user clicks
 3: // the mouse in the close box.
 4: 
 5: // Written by Wayne Pollock, Tampa, FL USA, 1999
 6: 
 7: import java.awt.*;
 8: import java.awt.event.*;
 9: 
10: public class GUIGreet extends Frame {
11:     private String message = "Hello, World!";
12: 
13:     public GUIGreet () {
14:         setTitle( "A Friendly Greeting" );
15:         setSize( 300, 200 );
16:         setVisible( true );
17: 
18:         addWindowListener(
19:         new WindowAdapter()
20:             {  public void windowClosing( WindowEvent e )
21:                 {  System.exit( 0 );
22:                 }
23:             }
24:         );
25:     }
26: 
27:     public static void main ( String [] args ) {
28:         GUIGreet me = new GUIGreet();
29:     }
30: 
31:     public void paint ( Graphics g ) {
32:         g.setColor( Color.RED );
33:         g.drawRect( 30, 40, 240, 130 );
34:         g.setColor( Color.BLUE );
35:         g.setFont( new Font( "SansSerif", Font.BOLD, 24 ) );
36:         g.drawString( message, 70, 110 );  // Position determined
37:     }                                      // by trial and error!
38: }