Java Reference
In-Depth Information
Example 15−6: Soundmap.java (continued)
URL url;
public ImagemapRectangle(int x, int y, int w, int h, URL url) {
super(x, y, w, h);
this.url = url;
}
}
}
JAR Files
The Soundmap applet defined in the previous section requires four files to operate:
the class file for the applet itself, the class file for the nested class it contains, the
image file, and the sound clip file. It can be loaded using an <APPLET> tag like this:
<APPLET code="com/davidflanagan/examples/applet/Soundmap.class"
codebase="../../../../" width=288 height=288>
...
</APPLET>
When the applet is loaded in this manner, however, each of the four files is trans-
ferred in uncompressed form using a separate HTML request. As you might imag-
ine, this is quite inefficient.
As of Java 1.1, you can instead combine the four files into a single JAR file. This
single, compressed file (it is a ZIP file) can be transferred from web server to
browser much more efficiently. To create a JAR file, use the jar tool, which has a
syntax reminiscent of the Unix tar command:
% jar cf applets.jar com/davidflanagan/examples/applet
This command creates a new file, applets.jar , that contains all the files in the com/
davidflanagan/examples/applet directory.
To use a JAR file, you specify it as the value of the ARCHIVE attribute of the
<APPLET> tag:
<APPLET code="com/davidflanagan/examples/applet/Soundmap.class"
archive="applets.jar" width=288 height=288>
...
</APPLET>
Note that the ARCHIVE attribute does not replace the CODE attribute. ARCHIVE speci-
fies where to look for files, but CODE is still required to tell the browser which file
in the archive is the applet class file to be executed. The ARCHIVE attribute may
actually specify a comma-separated list of JAR files. The web browser or applet
viewer searches these archives for any files the applet requires. If a file is not
found in an archive, however, the browser falls back on its old behavior and
attempts to load the file from the web server using a separate HTTP request.
Search WWH ::




Custom Search