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: {
12: private String message = "Hello, World!";
13:
14: public GUIGreet ()
15: {
16: setTitle( "A Friendly Greeting" );
17: setSize( 300, 200 );
18: setVisible( true );
19:
20: addWindowListener(
21: new WindowAdapter()
22: { public void windowClosing( WindowEvent e )
23: { System.exit( 0 );
24: }
25: }
26: );
27: }
28:
29: public static void main ( String [] args )
30: {
31: GUIGreet me = new GUIGreet();
32: }
33:
34: public void paint ( Graphics g )
35: {
36: g.setColor( Color.RED );
37: g.drawRect( 30, 40, 240, 130 );
38: g.setColor( Color.BLUE );
39: g.setFont( new Font( "SansSerif", Font.BOLD, 24 ) );
40: g.drawString( message, 70, 110 ); // Position determined
41: } // by trial and error!
42: }