Contents    Previous    Next

Adding an Applet to a Page

By following the steps on this page, you can add an applet to an HTML page. This example uses the ImageLoopItem applet, which performs animation. We supply another applet, AudioItem, that you can use to play sounds.

  1. If you don't already have a directory (folder) for your HTML pages, create one. (Here are the platform-specific details.)

  2. In the HTML directory you created in step 1, create a file named AnApplet.html. Put the following text in it:
        <HTML>
        <HEAD>
        <TITLE> An Applet </TITLE>
        </HEAD>
        
        <BODY>
        Here is an applet:
        <APP CLASS="ImageLoopItem"
             SRC="doc:/demo/"
             IMG="images/duke">
        </BODY>
        </HTML>
    
    The general syntax of the APP HTML tag (which you use to add applets to a page) is discussed later in this document.

  3. Load the new file into HotJava by entering its URL in the Document URL field near the top of the HotJava window. For example:
        file:/home/kwalrath/Html/AnApplet.html
    
    or, for files on Windows NT:
        file:///c:/Html/AnApplet.html
    
    Information on URLs is available in various places on the Internet, such as from the NCSA in A Beginner's Guide to URLs.
Once you've successfully completed these steps, you should see the following in the HotJava page that comes up:
Here is an applet:

You can sometimes make the display of an applet more attractive by specifying the width and height of the applet's display area. For example, the following HTML text

    <APP CLASS="ImageLoopItem"
         SRC="doc:/demo/"
         IMG="doc:/demo/images/duke"
	 WIDTH=55
	 HEIGHT=68>
results in a better page layout when the applet's display is delayed:

For more information on applets provided with this release, choose the Next link below. Or, you can skip forward to learn about writing applets.


Contents    Previous    Next