javax.swing
Class JApplet

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--javax.swing.JApplet
All Implemented Interfaces:
Accessible, java.awt.image.ImageObserver, MenuContainer, RootPaneContainer, Serializable

public class JApplet
extends java.applet.Applet
implements Accessible, RootPaneContainer

Unsafe: An extended version of java.applet.Applet that adds support for the JFC/Swing component architecture. You can find task-oriented documentation about using JApplet in The Java Tutorial, in the section How to Make Applets.

The JApplet class is slightly incompatible with java.applet.Applet. JApplet contains a JRootPane as it's only child. The contentPane should be the parent of any children of the JApplet. This is different than java.applet.Applet, e.g. to add a child to an an java.applet.Applet you'd write:

       applet.add(child);
 
However using JApplet you need to add the child to the JApplet's contentPane instead:
       applet.getContentPane().add(child);
 
The same is true for setting LayoutManagers, removing components, listing children, etc. All these methods should normally be sent to the contentPane() instead of the JApplet itself. The contentPane() will always be non-null. Attempting to set it to null will cause the JApplet to throw an exception. The default contentPane() will have a BorderLayout manager set on it.

Please see the JRootPane documentation for a complete description of the contentPane, glassPane, and layeredPane properties.

For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JApplet key assignments.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder.

Version:
1.55 01/19/03
Author:
Arnaud Weber
See Also:
Serialized Form

Field Summary
protected  AccessibleContext accessibleContext
           
protected  JRootPane rootPane
           
protected  boolean rootPaneCheckingEnabled
           
 
Fields inherited from class java.awt.Panel
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
JApplet()
          Enabled: Creates a swing applet instance.
 
Method Summary
protected  void addImpl(Component comp, Object constraints, int index)
          By default, children may not be added directly to a this component, they must be added to its contentPane instead.
protected  JRootPane createRootPane()
          Called by the constructor methods to create the default rootPane.
private  Error createRootPaneException(String op)
          Create an runtime exception with a message like:
 AccessibleContext getAccessibleContext()
          Suppressed: Gets the AccessibleContext associated with this JApplet.
 Container getContentPane()
          Enabled: Returns the contentPane object for this applet.
 Component getGlassPane()
          Suppressed: Returns the glassPane object for this applet.
 JMenuBar getJMenuBar()
          Enabled: Returns the menubar set on this applet.
 JLayeredPane getLayeredPane()
          Suppressed: Returns the layeredPane object for this applet.
 JRootPane getRootPane()
          Suppressed: Returns the rootPane object for this applet.
protected  boolean isRootPaneCheckingEnabled()
           
protected  String paramString()
          Returns a string representation of this JApplet.
 void remove(Component comp)
          Enabled: Removes the specified component from this container.
 void setContentPane(Container contentPane)
          Enabled: Sets the contentPane property.
 void setGlassPane(Component glassPane)
          Suppressed: Sets the glassPane property.
 void setJMenuBar(JMenuBar menuBar)
          Enabled: Sets the menubar for this applet.
 void setLayeredPane(JLayeredPane layeredPane)
          Suppressed: Sets the layeredPane property.
 void setLayout(LayoutManager manager)
          Enabled: By default the layout of this component may not be set, the layout of its contentPane should be set instead.
protected  void setRootPane(JRootPane root)
          Sets the rootPane property.
protected  void setRootPaneCheckingEnabled(boolean enabled)
          If true then calls to add() and setLayout() will cause an exception to be thrown.
 void update(Graphics g)
          Enabled: Just calls paint(g).
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, get, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, iterate, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, size, transferFocusBackward, transferFocusDownCycle, 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, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, isOpaque, 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, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, toString, transferFocus, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rootPane

protected JRootPane rootPane
See Also:
getRootPane(), setRootPane(javax.swing.JRootPane)

rootPaneCheckingEnabled

protected boolean rootPaneCheckingEnabled
See Also:
isRootPaneCheckingEnabled(), setRootPaneCheckingEnabled(boolean)

accessibleContext

protected AccessibleContext accessibleContext
Constructor Detail

JApplet

public JApplet()
        throws HeadlessException
Enabled: Creates a swing applet instance.

This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.

See Also:
java.awt.GraphicsEnvironment#isHeadless, JComponent.getDefaultLocale()
Method Detail

createRootPane

protected JRootPane createRootPane()
Called by the constructor methods to create the default rootPane.


update

public void update(Graphics g)
Enabled: Just calls paint(g). This method was overridden to prevent an unnecessary call to clear the background.

Overrides:
update in class Container
Parameters:
g - the specified Graphics window
See Also:
Component.update(Graphics)

setJMenuBar

public void setJMenuBar(JMenuBar menuBar)
Enabled: Sets the menubar for this applet.

See Also:
getJMenuBar()

getJMenuBar

public JMenuBar getJMenuBar()
Enabled: Returns the menubar set on this applet.

See Also:
setJMenuBar(javax.swing.JMenuBar)

isRootPaneCheckingEnabled

protected boolean isRootPaneCheckingEnabled()
Returns:
true if add and setLayout should be checked
See Also:
addImpl(java.awt.Component, java.lang.Object, int), setLayout(java.awt.LayoutManager), setRootPaneCheckingEnabled(boolean)

setRootPaneCheckingEnabled

protected void setRootPaneCheckingEnabled(boolean enabled)
If true then calls to add() and setLayout() will cause an exception to be thrown.

See Also:
addImpl(java.awt.Component, java.lang.Object, int), setLayout(java.awt.LayoutManager), isRootPaneCheckingEnabled()

createRootPaneException

private Error createRootPaneException(String op)
Create an runtime exception with a message like:
 "Do not use JApplet.add() use JApplet.getContentPane().add() instead"
 


addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
By default, children may not be added directly to a this component, they must be added to its contentPane instead. For example:
 thiComponent.getContentPane().add(child)
 
An attempt to add to directly to this component will cause an runtime exception to be thrown. Subclasses can disable this behavior.

Overrides:
addImpl in class Container
Parameters:
comp - the component to be added
constraints - an object expressing layout constraints for this component
index - the position in the container's list at which to insert the component, where -1 means append to the end
See Also:
setRootPaneCheckingEnabled(boolean)

remove

public void remove(Component comp)
Enabled: Removes the specified component from this container.

Overrides:
remove in class Container
Parameters:
comp - the component to be removed
See Also:
Container.add(java.awt.Component)

setLayout

public void setLayout(LayoutManager manager)
Enabled: By default the layout of this component may not be set, the layout of its contentPane should be set instead. For example:
 thisComponent.getContentPane().setLayout(new GridLayout(1, 2))
 
An attempt to set the layout of this component will cause an runtime exception to be thrown. Subclasses can disable this behavior.

Overrides:
setLayout in class Container
Parameters:
manager - the specified layout manager
See Also:
setRootPaneCheckingEnabled(boolean)

getRootPane

public JRootPane getRootPane()
Suppressed: Returns the rootPane object for this applet.

Specified by:
getRootPane in interface RootPaneContainer
Returns:
this components single JRootPane child.
See Also:
setRootPane(javax.swing.JRootPane), RootPaneContainer.getRootPane()

setRootPane

protected void setRootPane(JRootPane root)
Sets the rootPane property. This method is called by the constructor.

Parameters:
root - the rootPane object for this applet
See Also:
getRootPane()

getContentPane

public Container getContentPane()
Enabled: Returns the contentPane object for this applet.

Specified by:
getContentPane in interface RootPaneContainer
Returns:
the value of the contentPane property.
See Also:
setContentPane(java.awt.Container), RootPaneContainer.getContentPane()

setContentPane

public void setContentPane(Container contentPane)
Enabled: Sets the contentPane property. This method is called by the constructor.

Specified by:
setContentPane in interface RootPaneContainer
Parameters:
contentPane - the contentPane object for this applet
See Also:
getContentPane(), RootPaneContainer.setContentPane(java.awt.Container)

getLayeredPane

public JLayeredPane getLayeredPane()
Suppressed: Returns the layeredPane object for this applet.

Specified by:
getLayeredPane in interface RootPaneContainer
Returns:
the value of the layeredPane property.
See Also:
setLayeredPane(javax.swing.JLayeredPane), RootPaneContainer.getLayeredPane()

setLayeredPane

public void setLayeredPane(JLayeredPane layeredPane)
Suppressed: Sets the layeredPane property. This method is called by the constructor.

Specified by:
setLayeredPane in interface RootPaneContainer
Parameters:
layeredPane - the layeredPane object for this applet
See Also:
getLayeredPane(), RootPaneContainer.setLayeredPane(javax.swing.JLayeredPane)

getGlassPane

public Component getGlassPane()
Suppressed: Returns the glassPane object for this applet.

Specified by:
getGlassPane in interface RootPaneContainer
Returns:
the value of the glassPane property.
See Also:
setGlassPane(java.awt.Component), RootPaneContainer.getGlassPane()

setGlassPane

public void setGlassPane(Component glassPane)
Suppressed: Sets the glassPane property. This method is called by the constructor.

Specified by:
setGlassPane in interface RootPaneContainer
Parameters:
glassPane - the glassPane object for this applet
See Also:
getGlassPane(), RootPaneContainer.setGlassPane(java.awt.Component)

paramString

protected String paramString()
Returns a string representation of this JApplet. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
paramString in class Container
Returns:
a string representation of this JApplet.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this JApplet. For JApplets, the AccessibleContext takes the form of an AccessibleJApplet. A new AccessibleJApplet instance is created if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class java.applet.Applet
Returns:
an AccessibleJApplet that serves as the AccessibleContext of this JApplet


comments?