Java Reference
In-Depth Information
<param name=”questions” value=”introquestions.txt”>
<p>You must have a browser that supports applets
to play Java Jeopardy.</p>
</applet>
</body>
</html>
No matter where this HTML document is located, the JeopardyApplet can
be found because the codebase attribute is defined. Notice that the Jeop-
ardyApplet uses an archive named jeopardy.jar, which contains several other
.class files as well as a file named introquestions.txt that contains the questions
for the game. This example also uses a parameter to denote this filename,
which allows the questions to be easily changed.
An applet can determine its document base and code base by using the
following methods, which are found in the Applet class.
public URL getDocumentBase(). Returns a java.net.URL object,
which represents the document base of the page that embeds
this applet
public URL getCodeBase(). Returns a java.net.URL object, which
represents the location where this applet is located
These are useful methods when developing applets, especially when you
need an applet to locate another file or document. At development time,
the applet author does not need to know the URL of the location where
the applet is to be deployed, nor does the applet author need to know the
location of the Web page that will be embedding the applet. Both of their
URLs can be obtained by using the getCodeBase() and getDocumentBase()
methods, respectively. The upcoming Displaying Images and Playing Audio
sections contain typical uses of these methods.
The appletviewer Tool
The J2SDK comes with a tool known as appletviewer that is used for testing
applets during their development stage. The appletviewer tool opens an
HTML file, but it ignores all <html> tags except for those pertaining to applets.
Figure 14.9 shows the options of the appletviewer tool.
Search WWH ::




Custom Search