Adding Java Applets to the Page
Java applets are self-contained programs written in the Java programming language, that can be placed inline on a web page just like a graphic. There are lots of Java applets available on the Web for free from Java library sites such as the JavaBoutique ((http://javaboutique.internet.com).
Most Java applet instructions require that you add the applet to the
page using the handy <applet> tag (made just
for the job!). However, the HTML 4.0 Spec recommends that applets be
added using the <object> tag instead,
although this is problematic in that some browsers don’t
recognize the <object> tag when used with
Java. In this section, we will focus on the
<applet> method.
The <applet> tag is a container for any
number of parameter (<param>) tags. The
following is an example of how an <applet>
tag for a game might look:
<APPLET CODEBASE=class CODE="Wacky.class" WIDTH=300 HEIGHT=400> <PARAM NAME="Delay" VALUE="250"> <PARAM NAME="Time" VALUE="120"> <PARAM NAME="PlaySounds" VALUE="YES"> </APPLET>
The opening applet tag contains a number of standard attributes:
-
code Tells the browser which applet will be used. Applets end with the suffix
.classor.jar. This attribute is required.-
codebase This tells the browser in which directory to find the applets. If the applets are in the same directory as the page, the
codebaseattribute is not necessary.-
widthandheight These specify the pixel dimensions of the “window” the applet will occupy. These attributes are required ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access