java.applet

Class Applet

public class Applet extends Panel

This is the base applet class. An applet is a Java program that runs inside a web browser or other applet viewer in a restricted environment.

To be useful, a subclass should override at least start(). Also useful are init, stop, and destroy for control purposes, and getAppletInfo and getParameterInfo for descriptive purposes.

Since: 1.0

UNKNOWN: updated to 1.4

Nested Class Summary
protected classApplet.AccessibleApplet
This class provides accessibility support for Applets, and is the runtime type returned by {@link #getAccessibleContext()}.
Constructor Summary
Applet()
Default constructor for subclasses.
Method Summary
voiddestroy()
This method is called when the applet is being unloaded.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this applet, creating one if necessary.
AppletContextgetAppletContext()
Returns the applet context for this applet.
StringgetAppletInfo()
Returns a descriptive string with applet defined information.
AudioClipgetAudioClip(URL url)
Returns an audio clip from the specified URL.
AudioClipgetAudioClip(URL url, String name)
Returns an audio clip from the specified absolute URL, and relative path from that URL.
URLgetCodeBase()
Returns the URL of the code base for this applet.
URLgetDocumentBase()
Returns the basename URL of the document this applet is embedded in.
ImagegetImage(URL url)
Returns an image from the specified URL.
ImagegetImage(URL url, String name)
Returns an image from the specified absolute URL, and relative path from that URL.
LocalegetLocale()
Returns the locale for this applet, if it has been set.
StringgetParameter(String name)
Returns the value of the specified parameter that was specified in the <APPLET> tag for this applet.
String[][]getParameterInfo()
Returns a list of parameters this applet supports.
voidinit()
This method is called when the applet is first loaded, before start().
booleanisActive()
Tests whether or not this applet is currently active.
static AudioClipnewAudioClip(URL url)
Returns an audio clip from the specified URL.
voidplay(URL url)
Loads and plays the audio clip pointed to by the specified URL.
voidplay(URL url, String name)
Loads and plays the audio clip pointed to by the specified absolute URL, and relative path from that URL.
voidresize(int width, int height)
Requests that the applet window for this applet be resized.
voidresize(Dimension dim)
Requests that the applet window for this applet be resized.
voidsetStub(AppletStub stub)
The browser calls this method to set the applet's stub, which is the low level interface to the browser.
voidshowStatus(String message)
Displays the specified message in the status window if that window exists.
voidstart()
This method is called when the applet should start running.
voidstop()
This method is called when the applet should stop running.

Constructor Detail

Applet

public Applet()
Default constructor for subclasses.

Throws: HeadlessException if in a headless environment

Method Detail

destroy

public void destroy()
This method is called when the applet is being unloaded. The default implementation does nothing; override for your applet to clean up resources on exit.

See Also: init start stop

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this applet, creating one if necessary. This always returns an instance of {@link AccessibleApplet}.

Returns: the accessibility context of this applet

Since: 1.3

getAppletContext

public AppletContext getAppletContext()
Returns the applet context for this applet.

Returns: the applet context for this applet

getAppletInfo

public String getAppletInfo()
Returns a descriptive string with applet defined information. The implementation in this class returns null, so subclasses must override to return information.

Returns: a string describing the author, version, and applet copyright

getAudioClip

public AudioClip getAudioClip(URL url)
Returns an audio clip from the specified URL. Note that the clip is not actually retrieved until the applet attempts to play it, so this method returns immediately.

Parameters: url the URL of the audio clip

Returns: the retrieved audio clip

Throws: NullPointerException if url is null

getAudioClip

public AudioClip getAudioClip(URL url, String name)
Returns an audio clip from the specified absolute URL, and relative path from that URL. Note that the clip is not actually retrieved until the applet attempts to play it, so this method returns immediately. This calls getAudioClip(new URL(url, name)), but if building the new URL fails, this returns null.

Parameters: url the base URL of the audio clip name the name of the clip relative to the URL

Returns: the retrieved audio clip, or null on failure

See Also: getAudioClip

getCodeBase

public URL getCodeBase()
Returns the URL of the code base for this applet.

Returns: the URL of the code base for this applet

getDocumentBase

public URL getDocumentBase()
Returns the basename URL of the document this applet is embedded in. This is everything up to the final '/'.

Returns: the URL of the document this applet is embedded in

See Also: getCodeBase

getImage

public Image getImage(URL url)
Returns an image from the specified URL. Note that the image is not actually retrieved until the applet attempts to display it, so this method returns immediately.

Parameters: url the URL of the image

Returns: the retrieved image

Throws: NullPointerException if url is null

getImage

public Image getImage(URL url, String name)
Returns an image from the specified absolute URL, and relative path from that URL. Note that the image is not actually retrieved until the applet attempts to display it, so this method returns immediately. This calls getImage(new URL(url, name)), but if building the new URL fails, this returns null.

Parameters: url the base URL of the image name the name of the image relative to the URL

Returns: the retrieved image, or null on failure

See Also: getImage

getLocale

public Locale getLocale()
Returns the locale for this applet, if it has been set. If no applet specific locale has been set, the default locale is returned.

Returns: the locale for this applet

Since: 1.1

See Also: setLocale

getParameter

public String getParameter(String name)
Returns the value of the specified parameter that was specified in the <APPLET> tag for this applet.

Parameters: name the parameter name

Returns: the parameter value, or null if the parameter does not exist

Throws: NullPointerException if name is null

getParameterInfo

public String[][] getParameterInfo()
Returns a list of parameters this applet supports. Each element of the outer array is an array of three strings with the name of the parameter, the data type or valid values, and a description. This method is optional and the default implementation returns null.

Returns: the list of parameters supported by this applet

init

public void init()
This method is called when the applet is first loaded, before start(). The default implementation does nothing; override to do any one-time initialization.

See Also: start stop destroy

isActive

public boolean isActive()
Tests whether or not this applet is currently active. An applet is active just before the browser invokes start(), and becomes inactive just before the browser invokes stop().

Returns: true if this applet is active

newAudioClip

public static final AudioClip newAudioClip(URL url)
Returns an audio clip from the specified URL. This clip is not tied to any particular applet.

Parameters: url the URL of the audio clip

Returns: the retrieved audio clip

Throws: NullPointerException if url is null

Since: 1.2

See Also: getAudioClip

play

public void play(URL url)
Loads and plays the audio clip pointed to by the specified URL. This does nothing if the URL does not point to a valid audio clip.

Parameters: url the URL of the audio clip

Throws: NullPointerException if url is null

See Also: getAudioClip

play

public void play(URL url, String name)
Loads and plays the audio clip pointed to by the specified absolute URL, and relative path from that URL. This does nothing if the URL cannot be constructed, or if it does not point to a valid audio clip.

Parameters: url the base URL of the audio clip name the name of the audio clip relative to the URL

See Also: Applet play

resize

public void resize(int width, int height)
Requests that the applet window for this applet be resized.

Parameters: width the new width in pixels height the new height in pixels

resize

public void resize(Dimension dim)
Requests that the applet window for this applet be resized.

Parameters: dim the requested dimensions

Throws: NullPointerException if dim is null

setStub

public final void setStub(AppletStub stub)
The browser calls this method to set the applet's stub, which is the low level interface to the browser. Manually setting this to null is asking for problems down the road.

Parameters: stub the applet stub for this applet

showStatus

public void showStatus(String message)
Displays the specified message in the status window if that window exists.

Parameters: message the status message, may be null

start

public void start()
This method is called when the applet should start running. This is normally each time a web page containing it is loaded. The default implemention does nothing; override for your applet to be useful.

See Also: init stop destroy

stop

public void stop()
This method is called when the applet should stop running. This is normally when the next web page is loaded. The default implementation does nothing; override for your applet to stop using resources when it is no longer visible, but may be restarted soon.

See Also: init start destroy