Embedding your Java Applet in a Web Page
To learn how to create web pages, see my notes on Hypertext Markup Language (HTML). For example, using a text editor (save as text if you use a word processor), create a file with a .html extension with the following contents:
<html>
<head>
<title>Title of your document</title>
</head>
<body>
<hr />
<applet code = "YourApplet.class" width = "300" height = "200" >
</applet>
<hr />
</body>
</html>
In the above code, <hr /> stands for a horizontal rule across the page.
Save your web page in the same directory as the Java applet code, To view it using the JDK appletviewer instead of your browser:
appletviewer YourApplet.html
The <applet> tag specifies the file containing your bytecode. 'width = "300" height = "200"' specifies the width and height in pixels of the region of the screen that the applet will use. You must specify these. The results of the applet will be displayed between the horizontal lines.
Here is my first applet:
For those interested, here is it's code:
import java.applet.Applet;
import java.awt.Graphics;
public class SuesFirstApplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("My name is Sue, how do you do!", 20, 90);
}
}
