Java Reference
In-Depth Information
The problem with running applets in this way is that every single file an applet
requires—helper classes, images, audio files, text files, or anything else—requires a sep-
arate connection from a web browser to the server containing the file. This can signifi-
cantly increase the amount of time it takes to download an applet and everything it needs
to run.
If you can reduce the number of files the browser has to load from the server by putting
many files into one Java archive, your applet can be downloaded and run by a web
browser more quickly. If the files in a Java archive are compressed, it loads even more
quickly.
After you create a Java archive, the archive attribute is used with the applet tag to show
where the archive can be found. You can use Java archives with an applet with tags such
as the following:
<applet code=”MusicLoop.class” archive=”MusicLoop.jar” width=”45” height=”42”>
</applet>
This tag specifies that an archive called MusicLoop.jar contains files used by the applet.
Browsers and browsing tools that support JAR files will look inside the archive for files
that are needed as the applet runs.
CAUTION
Although a Java archive can contain class files, the archive
attribute does not remove the need for the code attribute. A
browser still needs to know the name of the applet's main class
file to load it.
When using an object tag to display an applet that uses a JAR file, the applet's archive
file is specified as a parameter using the param tag. The tag should have the name
attribute “archive” and a value attribute with the name of the archive file.
The following example is a rewrite of the preceding example to use object instead of
applet :
<object code=”MusicLoop.class” width=”45” height=”42”>
<param name=”archive” value=”MusicLoop.jar”>
</object>
Search WWH ::




Custom Search