Java Reference
In-Depth Information
G
Java Applets
In Chapter 2 we presented the basic concept of an applet, including how an applet
differs from an application and how an applet is referenced in an HTML page so
that it can be executed in a browser. The applet examples in Chapter 2 present
simple drawings. We revisited the concept of an applet in Chapter 9, exploring
how applets are a good example of inheritance. This appendix fills in some other
details about Java applets.
The example applets in Chapter 2 override the paint method of the JApplet
class. An applet has several other methods that perform specific duties. Because
an applet is designed to work with Web pages, some applet methods are specifi-
cally designed with that concept in mind. Figure G.1 lists several applet methods.
public void init ()
Initializes the applet. Called just after the applet is loaded.
public void start ()
Starts the applet. Called just after the applet is made active.
public void stop ()
Stops the applet. Called just after the applet is made inactive.
public void destroy ()
Destroys the applet. Called when the browser is exited.
public URL getCodeBase ()
Returns the URL at which this applet's bytecode is located.
public URL getDocumentBase ()
Returns the URL at which the HTML document containing this applet is
located.
public AudioClip getAudioClip (URL url, String name)
Retrieves an audio clip from the specified URL.
public Image getImage (URL url, String name)
Retrieves an image from the specified URL.
FIGURE G.1 Some methods of the Applet class
693
 
 
Search WWH ::




Custom Search