010615
J. W. Rider

Class Applet

An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application.

The Applet class must be the superclass of any applet that is to be embedded in a Web page or viewed by the Java Applet Viewer. The Applet class provides a standard interface between applets and their environment.

The Applet class doesn't provide any genuine applicability on its own. Its purpose is to provide a super class from which custom applet classes are extended.

Applet Method Summary
Overridable
These methods should be overridden by the custom applet class in order to do anything useful. The default behavior for these methods is to do nothing.
void init() Called by the browser or applet viewer to inform this applet that it has been loaded into the system.
void start() Called by the browser or applet viewer to inform this applet that it should start its execution.
void stop() Called by the browser or applet viewer to inform this applet that it should stop its execution.
void destroy() Called by the browser or applet viewer to inform this applet that it is being reclaimed and that it should destroy any resources that it has allocated.
String getAppletInfo() Returns information about this applet.
String[][] getParameterInfo() Returns information about the parameters than are understood by this applet.
void paint(Graphics g)

Semi-overridable

Methods that are known to be usefully overridden, but you usually do not have to do so.
void update(Graphics g)paint() is not called directly. This is the method that calls paint(). You may need to override this method for animation and double buffering graphics.

Informational

Call these methods to learn about the environment in which the applet is running.
AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with this Applet.
AppletContext getAppletContext() Determines this applet's context, which allows the applet to query and affect the environment in which it runs. For example, you'll need to know the applet context in order to make the web browser go to another web page.
URL getCodeBase() Gets the base URL.
URL getDocumentBase() Returns an absolute URL naming the directory of the document in which the applet is embedded.
Locale getLocale() Gets the Locale for the applet, if it has been set.
String getParameter(String name) Returns the value of the named parameter in the HTML tag. Case insensitive.
boolean isActive() Determines if this applet is active.An applet is marked active just before its start method is called. It becomes inactive just before its stop method is called.

Utility

Methods that you would call from within the methods that you create. Not all of these are defined at the "Applet" class. Many of these methods are defined higher in the Applet ancestry.
AudioClip getAudioClip(URL url) Returns the AudioClip object specified by the URL argument.
AudioClip getAudioClip(URL url, String name) Returns the AudioClip object specified by the URL and name arguments.
Color getBackground() Defines the Background color property.
void setBackground(Color x)
Color getForeground() Defines the Foreground color property.
void setForeground(Color x)
Image getImage(URL url) Returns an Image object that can then be painted on the screen.
Image getImage(URL url, String name) Returns an Image object that can then be painted on the screen.
static AudioClip newAudioClip(URL url) Get an audio clip from the given URL.
void play(URL url) Plays the audio clip at the specified absolute URL, or a relative URL and a specifier that is relative to it.
void play(URL url, String name)
void repaint() Requests that the paint() method get called either as soon as possible, or within a period of time.
void repaint(long millisec)
void repaint(x,y,w,h)
void repaint(milli, x,y,w,h)
Dimension size()[JDK 1.0] returns the size of the applet on the screen.
Dimension getSize() [JDK 1.1]
void showStatus(String msg) Requests that the argument string be displayed in the "status window". Most browsers provide a status window, but the appletviewer does not. You should not overuse this method.

public void init()

Called by the browser or applet viewer to inform this applet that it has been loaded into the system. It is always called before the first time that the start method is called. A subclass of Applet should override this method if it has initialization to perform. For example, an applet with threads would use the init method to create the threads and the destroy method to kill them.

The default implementation of this method does nothing.

public void start()

Called by the browser or applet viewer to inform this applet that it should start its execution. It is called after the init method and each time the applet is revisited in a Web page. A subclass of Applet should override this method if it has any operation that it wants to perform each time the Web page containing it is visited. For example, an applet with animation might want to use the start method to resume animation, and the stop method to suspend the animation.

The default implementation of this method does nothing.

public void stop()

Called by the browser or applet viewer to inform this applet that it should stop its execution. It is called when the Web page that contains this applet has been replaced by another page, and also just before the applet is to be destroyed. A subclass of Applet should override this method if it has any operation that it wants to perform each time the Web page containing it is no longer visible. For example, an applet with animation might want to use the start method to resume animation, and the stop method to suspend the animation.

The implementation of this method does nothing.

public void destroy()

Called by the browser or applet viewer to inform this applet that it is being reclaimed and that it should destroy any resources that it has allocated. The stop method will always be called before destroy. A subclass of Applet should override this method if it has any operation that it wants to perform before it is destroyed. For example, an applet with threads would use the init method to create the threads and the destroy method to kill them.

The default implementation of this method does nothing.

public String getAppletInfo()

Returns information about this applet. An applet should override this method to return a String containing information about the author, version, and copyright of the applet. The default implementation of this method provided by the Applet class returns null.

public String[][] getParameterInfo()

Returns information about the parameters than are understood by this applet. An applet should override this method to return an array of Strings describing these parameters. Each element of the array should be a set of three Strings containing the name, the type, and a description. For example:

 String pinfo[][] = {
	 {"fps",    "1-10",    "frames per second"},
	 {"repeat", "boolean", "repeat image loop"},
	 {"imgs",   "url",     "images directory"}
 };

The default implementation of this method returns null. 1