After we create a class or classes that contain our applet and compile them into class files as we would any other Java program, we have to create a Web page that will hold that applet by using the HTML language.
There is a special HTML tag for including applets in Web pages; Java-enabled browsers use the information contained in that tag to locate the compiled class files and execute the applet itself.
The <APPLET> Tag
To include an applet on a Web page, use the <APPLET> tag. <APPLET> is a special extension to HTML for including applets in Web pages.
A simple HTML page.
<TITLE>This page has an applet on it</TITLE>
<P>My second Java applet says:
<BR><APPLET CODE=”HelloAgainApplet.class” WIDTH=200 HEIGHT=50>
1. The CODE attribute indicates the name of the class file that contains this applet, including the .class extension. In this case, the class file must be in the same directory as this HTML file. To indicate applets are in a specific directory, use CODEBASE, described later today.
2. WIDTH and HEIGHT are required and are used to indicate the bounding box of the applet-that is, how big a box to draw for the applet on the Web page. Be sure we set WIDTH and HEIGHT to be an appropriate size for the applet; depending on the browser, if our applet draws outside the boundaries of the space you’ve given it, we may not be able to see or get to those parts of the applet outside the bounding box.
3. The text between the <APPLET> and </APPLET> tags is displayed by browsers that do not understand the <APPLET> tag (which includes most browsers that are not Java aware). Because our page may be viewed in many different kinds of browsers, it is a very good idea to include some sort of alternate text or HTML tags here so that readers of your page who don’t have Java will see something other than a blank line.
4. Note that the <APPLET> tag, like the <IMG> tag itself, is not a paragraph, so it should be enclosed inside a more general text tag, such as <P> or one of the heading tags (<H1>, <H2>, and so on).