A Better Hello World Applet

The second example is a simple applet that displays the a string which is passed as a parameter instead of a constant string.

import java.applet.Applet;
import java.awt.Graphics;

public class DrawStringApplet extends Applet {

    private String inputstring;

    public void init() {
	inputstring = getParameter("string");
    }
	
    public void paint(Graphics g) {
	g.drawString(inputstring, 50, 25);
    }
}

When an applet is first loaded by the browser its init method is called.