import java.awt.*;

public class SqrtList extends java.applet.Applet {
    public void paint(Graphics g) {
	g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
	for (float i = 1; i <= 10; i++)
	    g.drawString("sqrt(" + i + ") = " + Math.sqrt(i), 0, 
		(int)i * 16 - 3);

This is the code that specifies the Java code to run:

<APPLET CODEBASE=”java” CODE=”SqrtList” WIDTH=160 HEIGHT=162> <EM>You need a Java-aware browser</EM> </APPLET>

The <APPLET> tag specifies the class to load (the CODE= field), URL information (the CODEBASE= field) and the size of the region the applet will own. Notice that Java doesn’t exactly integrate with the rest of the page. Within that region of the page Java is king: it decides background color and fonts and does all the mouse and keyboard handling.

Parameters to the applet are placed in <PARAM> tags between the <APPLET> and </APPLET> tags. Anything else between these tags is ignored. It’s common to include some information here for display by browsers that don’t know about Java, since they’ll ignore the <APPLET> and <PARAM> tags and display whatever else they find there.


sqrt(1) = 1
sqrt(2) = 1.41421
sqrt(3) = 1.73205
sqrt(4) = 2
sqrt(5) = 2.23607
sqrt(6) = 2.44949
sqrt(7) = 2.64575
sqrt(8) = 2.82843
sqrt(9) = 3
sqrt(10) = 3.16228