java.applet
Class Applet

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
JApplet

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
See Also:
Serialized Form

Nested Class Summary
protected  class Applet.AccessibleApplet
          This class provides accessibility support for Applets, and is the runtime type returned by Component.getAccessibleContext().
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Applet()
          Default constructor for subclasses.
 
Method Summary
 void destroy()
          This method is called when the applet is being unloaded.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this applet, creating one if necessary.
 AppletContext getAppletContext()
          Returns the applet context for this applet.
 String getAppletInfo()
          Returns a descriptive string with applet defined information.
 AudioClip getAudioClip(URL url)
          Returns an audio clip from the specified URL.
 AudioClip getAudioClip(URL url, String name)
          Returns an audio clip from the specified absolute URL, and relative path from that URL.
 URL getCodeBase()
          Returns the URL of the code base for this applet.
 URL getDocumentBase()
          Returns the basename URL of the document this applet is embedded in.
 Image getImage(URL url)
          Returns an image from the specified URL.
 Image getImage(URL url, String name)
          Returns an image from the specified absolute URL, and relative path from that URL.
 Locale getLocale()
          Returns the locale for this applet, if it has been set.
 String getParameter(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.
 void init()
          This method is called when the applet is first loaded, before start().
 boolean isActive()
          Tests whether or not this applet is currently active.
static AudioClip newAudioClip(URL url)
          Returns an audio clip from the specified URL.
 void play(URL url)
          Loads and plays the audio clip pointed to by the specified URL.
 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.
 void resize(Dimension dim)
          Requests that the applet window for this applet be resized.
 void resize(int width, int height)
          Requests that the applet window for this applet be resized.
 void setStub(AppletStub stub)
          The browser calls this method to set the applet's stub, which is the low level interface to the browser.
 void showStatus(String message)
          Displays the specified message in the status window if that window exists.
 void start()
          This method is called when the applet should start running.
 void stop()
          This method is called when the applet should stop running.
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Applet

public Applet()
Default constructor for subclasses.

Throws:
HeadlessException - if in a headless environment
Method Detail

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

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

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()

getCodeBase

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

Returns:
the URL of the code base for this applet

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

getAppletContext

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

Returns:
the applet context for this applet

resize

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

Overrides:
resize in class Component
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.

Overrides:
resize in class Component
Parameters:
dim - the requested dimensions
Throws:
NullPointerException - if dim is null

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

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(URL)

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(URL)

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(URL)

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

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.

Overrides:
getLocale in class Component
Returns:
the locale for this applet
Since:
1.1
See Also:
Component.setLocale(Locale)

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

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(URL)

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:
getAudioClip(URL, String), play(URL)

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()

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()

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 Applet.AccessibleApplet.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class Panel
Returns:
the accessibility context of this applet
Since:
1.3