The basics - what goes into an applet

import java.awt.*;
import java.applet.*;

public class SimpleApplet extends Applet
{
	public void init()
	{
	}

	public void paint( Graphics g)
	{
	}

	public void destroy()
	{
	}
}
there are three basic methods that should be provided
public void init()
called when the applet is created, this is where any code to build a user interface should be placed.

public void paint( Graphics g)
the appearance of the applet.

public void destroy()
if anything needs to be done when the applet terminates, this is where it should be done. On the whole this isnt that important as when the applet goes, the garbage collector will clear up any memory that it owned


how to add an applet to a HTML page

once the soure for the applet has been compiled it can be embedded into a html page by using the <APPLET> tag:

<APPLET CODE=applet.class WIDTH=width HEIGHT=height>
<PARAM NAME=name1 VALUE=value1>
<PARAM NAME=name2 VALUE=value2>
<PARAM NAME=name3 VALUE=value3>
...
</APPLET>

However many sites disable java at the firewall so your applet may not appear to work in these cases. Most firewalls prevent java files from getting past them by looking for a ".class" extension. Both Netscape and Microsoft provide mechanisms to get around this.

Netscape Navigator

Internet Explorer
Microsoft's Internet explorer does not support the archive attribute of the <APPLET> tag. It uses CAB (Cabinet)


<PARAM>

The <PARAM> provides parameters that the applet should read in its init() method.

These generally control the applet's appearance and are not designed to be substitutes for a user interface.

public void init()
{
  String my_arg1, myarg2, my_arg3, ...;

  my_arg1 = getParameter("name1");
  my_arg2 = getParameter("name2");
  my_arg3 = getParameter("name3");
  ...
}


Converting parameters

public void init() {
  int value = default;

  my_arg =	getParameter("name1");
  if (my_arg == null){
	 try{
		value = Integer.parseInt(my_arg);
	 }
	 catch (NumberFormatException e) {
		value = default;
	 }
  }
}
The arguments are all passed as strings. If they need to be converted there should be adequate error handling to use default values if the conversion fails.