Source of HelloGUIApp2.java


  1: //HelloGUIApp2.java
  2: //An application to display "Hello, world!" in a window, in color.

  4: import java.awt.Frame;
  5: import java.awt.Graphics;
  6: import java.awt.Font;
  7: import java.awt.Color;


 10: public class HelloGUIApp2
 11: {
 12:     public static void main(String[] args)
 13:     {
 14:         GUI2 gui = new GUI2("Hello GUI Application Version 2");
 15:         gui.setSize(500, 100);
 16:         gui.setVisible(true);
 17:     }
 18: }


 21: class GUI2 extends Frame
 22: {
 23:     public GUI2(String s)
 24:     {
 25:         super(s);
 26:         setBackground(Color.yellow); // from Component
 27:     }

 29:     public void paint(Graphics g)
 30:     {
 31:         //Declare the font you want:
 32:         Font font = new Font("SanSerif", Font.BOLD, 18);

 34:         //Set font and color, and then display message
 35:         //on the screen at position (250, 150):
 36:         g.setFont(font);
 37:         g.setColor(Color.blue);
 38:         g.drawString("Hello, world!", 180, 65);
 39:     }
 40: }