The applet API lets you take advantage of the close relationship that applets have with Web browsers. The API is provided by the
java.appletpackage -- mainly by the
Appletclass and the
AppletContextinterface. Thanks to the applet API, applets can do the following:
- Be notified by the browser of milestones.
- Load data files specified relative to the URL of the applet or the page in which it is running.
- Display short status strings.
- Make the browser display a document.
- Find other applets running in the same page.
- Play sounds.
- Get parameters specified by the user in the
This lesson discusses each of these topics in turn, except for the milestone methods (
start, and so on), which are explained in Methods for Milestones. For information about how to use non-applet-specific API in an applet, see the Practical Considerations When Writing Applets lesson.
getDocumentBasemethods get information from the browser about where the applet and its HTML page came from. Finding and Loading Data Files describes how to use these methods to help you load your applet's data files, such as images.
Displaying Short Status Strings describes how to make an applet display a string on the status line of the application in which it is running.
Displaying Documents in the Browser tells you how to use the two
showDocumentmethods to request that the browser visit a particular URL.
getAppletsmethods, an applet can get the
Appletobjects for other applets running on the same page. Once an applet has another's
Appletobject, the applet can send messages to it. Sending Messages to Other Applets provides details and example applets that communicate with each other.
AudioClipinterface provide support for playing sounds. The Playing Sounds section tells you about this support and includes an example of using sound in an applet.
You can improve the versatility of your applet by providing parameters. Defining and Using Applet Parameters describes how to decide which parameters to provide, how to implement them, and how to inform the user about them.
Finally, Using the
<APPLET>Tag tells you how to customize an applet by editing its HTML tag.