Chapter 8. The java.applet PackageThe java.applet package is a small but important package that defines the Applet class--the superclass of all applets. It also defines the AppletContext and AppletStub interfaces, which are implemented by web browsers and other applet viewers. Finally, for lack of a better place, this package contains the AudioClip interface, which represents a sound to be played. Figure 8-1 shows the class hierarchy of this package. See Chapter 7, "Applets", for more details about applets. Figure 8-1. The java.applet package
This class implements an applet. To create your own applet, you should create a subclass of this class and override some or all of the following methods. Note that you never need to call these methods--they are called when appropriate by a web browser or other applet viewer. init() should perform any initialization for the applet; it is called when the applet first starts. destroy() should free up any resources that the applet is holding; it is called when the applet is about to be permanently stopped. start() is called to make applet start doing whatever it is that it does. Often, it starts a thread to perform an animation or similar task. stop() should temporarily stop the applet from executing. It is called when the applet temporarily becomes hidden or nonvisible. getAppletInfo() should return text suitable for display in an About dialog posted by the web browser or applet viewer. getParameterInfo() should return an arbitrary-length array of three-element arrays of strings, where each element describes one of the parameters that this applet understands. The three elements of each parameter description are strings that specify the parameter's name, type, and description, respectively. In addition to these methods, an applet typically overrides several of the methods of java.awt.Component, notably the paint() method to draw the applet on the screen. There are also several Applet methods that you do not override but may call from applet code: showStatus() displays text in the web browser or applet viewer's status line. getImage() and getAudioClip() read image (GIF and JPEG formats) and audio files (AU format) over the network and return corresponding Java objects. getParameter() looks up the value of a parameter specified with a <PARAM> tag within an <APPLET>/</APPLET> pair. getCodeBase() returns the base URL from which the applet's code was loaded, while getDocumentBase() returns the base URL from which the HTML document containing the applet was loaded. Finally, getAppletContext() returns an AppletContext object.
Hierarchy: Object-->Component(java.awt.image.ImageObserver,java.awt.MenuContainer,Serializable)-->Container-->java.awt.Panel-->Applet Subclasses: javax.swing.JApplet Passed To: java.beans.AppletInitializer.{activate(), initialize()}, org.omg.CORBA.ORB.{init(), set_parameters()} Returned By: AppletContext.getApplet()
This interface defines the methods that allow an applet to interact with the context in which it runs (usually a web browser or an applet viewer). The getAppletContext() method of Applet returns an object that implements the AppletContext interface. You can use an AppletContext to take advantage of a web browser's cache or display a message to the user in the web browser or applet viewer's message area. The getAudioClip() and getImage() methods may make use of a web browser's caching mechanism. showDocument() and showStatus() give an applet a small measure of control over the appearance of the browser or applet viewer. The getApplet() and getApplets() methods allow an applet to find out what other applets are running at the same time.
Returned By: Applet.getAppletContext(), AppletStub.getAppletContext()
This is an internal interface used when implementing an applet viewer.
Passed To: Applet.setStub()
This interface describes the essential methods that an audio clip must have. The getAudioClip() methods of Applet and AppletContext both return an object that implements this interface. The current Java SDK implementation of this interface works only with sounds encoded in AU format. The AudioClip interface is in the java.applet package only because there is no better place for it.
Returned By: Applet.{getAudioClip(), newAudioClip()}, AppletContext.getAudioClip() Copyright © 2001 O'Reilly & Associates. All rights reserved. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|