|
|
|
|||
|
Finding and Loading Data FilesWhenever an applet needs to load some data from a file that's specified with a relative URL (a URL that doesn't completely specify the file's location), the applet usually uses either the code base or the document base to form the complete URL. The code base, returned by theApplet getCodeBase method,
is a URL that specifies the directory
from which the applet's classes were loaded.
The document base,
returned by the Applet getDocumentBase method,
specifies the directory of the HTML page that contains the applet.
Unless the Data that the applet always needs, or needs to rely on as a backup, is usually specified relative to the code base. Data that the applet user specifies, often by using parameters, is usually specified relative to the document base. The Applet class defines convenient forms of
image-loading and sound-loading methods
that let you specify images and sounds relative to a base URL.
For example, assume an applet is set up
with one of the directory structures shown
in the following figure.
![]()
To create an Image image = getImage(getCodeBase(), "imgDir/a.gif"); | |||
|