java.applet

Class Applet

Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable
Known Direct 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 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(int width, int height)
Requests that the applet window for this applet be resized.
void
resize(Dimension dim)
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, getAccessibleContext

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, extends EventListener> T[] getListeners, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, 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, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Applet

public Applet()
Default constructor for subclasses.
Throws:
HeadlessException - if in a headless environment

Method Details

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 interface Panel
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

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

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 interface Component
Returns:
the locale for this applet
Since:
1.1

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.

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

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

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

resize

public void resize(int width,
                   int height)
Requests that the applet window for this applet be resized.
Overrides:
resize in interface 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 interface Component
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.

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.

Applet.java -- Java base applet class Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.