Source of HelloApplet3.java


  1: //HelloApplet3.java
  2: //An applet to display "Hello, world!" in a browser window.

  4: //<applet code="HelloApplet3.class"
  5: //        width="800"
  6: //        height="300">
  7: //</applet>

  9: import java.awt.*;
 10: import java.applet.*;

 12: public class HelloApplet3
 13: extends Applet
 14: {
 15:     //The paint method is automatically called by a browser.
 16:     //Here we override paint() method to automatically display
 17:     //information in the applet's window. The paint method
 18:     //is called automatically to display the graphics object.
 19:     public void paint(Graphics g)
 20:     {
 21:         //Declare the font you want:
 22:         Font font = new Font("Serif", Font.BOLD, 72);

 24:         //Set font and color, and then display message
 25:         //on the screen at position (175, 150):
 26:         g.setFont(font);
 27:         g.setColor(Color.red);
 28:         g.drawString("Hello, world!", 175, 150);

 30:         //The following line just provides a short delay.
 31:         double x; for (int i=1; i<=1000000000; i++) x=1.0;

 33:         g.setColor(Color.green);
 34:         g.drawString("Hello, world!", 175, 150);

 36:         //Another short delay, of the same duration.
 37:         for (int i=1; i<=1000000000; i++) x=1.0;

 39:         g.setColor(Color.blue);
 40:         g.drawString("Hello, world!", 175, 150);
 41:     }    
 42: }