showmesomejava.gif (6331 bytes) hairstyle1.gif (1911 bytes)

This HTML page contains:

Here's the Java applet:

Thomas Albert wrote the applet in Java, so only a Java-enabled browser can load it.

Source Code

Here is the source code that I compiled using javac, the Sun Microsystems bytecode compiler, to obtain the class file I reference in this HTML page.

/**
* Import classes from the package for user interface elements, awt
*/

import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;

/**
* Declare the applet. An applet must be a public class.
* My applet extends the applet class with my customizations.
*/

public class HelloAgainApplet extends java.applet.Applet {

/**
* Specify the appearance, content, and horizontal/vertical pixel 
* positions of the text strings the applet displays.
*/

Font f = new Font("TimesRoman", Font.BOLD, 30);
    public void paint(Graphics g) {
        g.setFont(f);
        g.setColor(Color.red);
        g.drawString("Hello from Thomas Albert.", 5, 50);
        g.drawString("I wrote this simple Java applet.", 10, 100);
        g.drawString("Here is the gist of the code:", 30, 150);
        g.drawString("(1) Import awt classes for Graphics, Font, and Color.", 40, 200);
        g.drawString("(2) Declare my extension to the applet class.", 40, 250);
        g.drawString("(3) Specify string appearance, content, and position.", 40, 300);
    }

Recipe

How did I do it?

  1. I started at Sun Microsystem's web site:  http://java.sun.com/docs/books/tutorial/index.html
  2. I downloaded the Java Developer Kit (jdk), which is 20 MB.
  3. I ran the setup program.
  4. I changed my system path so that it referenced the folder with Java binaries.
  5. I consulted three books:
  1. I wrote a text file with the .java extension.
  2. I compiled it so that it had the .class extension.
  3. I recompile many times until I cleaned out all the bugs caused by typographical errors and trial and error string positioning.
    NOTE: javac is a case-sensitive compiler.
  4. I uploaded to the web server the bytecode Java class file and this HTML file that references it with the <applet> tag.
  5. I tested the result by going to the URL and waiting for the Java virtual machine to load the page with the applet. [It was an iterative process.]