JavaTM 2 Platform
Std. Ed. v1.3.1

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, ImageObserver, MenuContainer, RootPaneContainer, Serializable

public class JApplet
extends Applet
implements Accessible, RootPaneContainer

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. A future release of Swing will provide support for long term persistence.

See Also:
Serialized Form

Inner Class Summary
protected  class JApplet.AccessibleJApplet
          This class implements accessibility support for the JApplet class.
 
Inner classes inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Inner classes inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
Field Summary
protected  AccessibleContext accessibleContext
           
protected  JRootPane rootPane
           
protected  boolean rootPaneCheckingEnabled
           
 
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
JApplet()
          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.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this JApplet.
 Container getContentPane()
          Returns the contentPane object for this applet.
 Component getGlassPane()
          Returns the glassPane object for this applet.
 JMenuBar getJMenuBar()
          Returns the menubar set on this applet.
 JLayeredPane getLayeredPane()
          Returns the layeredPane object for this applet.
 JRootPane getRootPane()
          Returns the rootPane object for this applet.
protected  boolean isRootPaneCheckingEnabled()
           
protected  String paramString()
          Returns a string representation of this JApplet.
protected  void processKeyEvent(KeyEvent e)
          Processes key events occurring on this component by dispatching them to any registered KeyListener objects.
 void remove(Component comp)
          Removes the specified component from this container.
 void setContentPane(Container contentPane)
          Sets the contentPane property.
 void setGlassPane(Component glassPane)
          Sets the glassPane property.
 void setJMenuBar(JMenuBar menuBar)
          Sets the menubar for this applet.
 void setLayeredPane(JLayeredPane layeredPane)
          Sets the layeredPane property.
 void setLayout(LayoutManager manager)
          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)
          Just calls paint(g).
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setFont, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, 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, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
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()
Creates a swing applet instance.
Method Detail

createRootPane

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

processKeyEvent

protected void processKeyEvent(KeyEvent e)
Description copied from class: Component
Processes key events occurring on this component by dispatching them to any registered KeyListener objects.

This method is not called unless key events are enabled for this component. Key events are enabled when one of the following occurs:

Overrides:
processKeyEvent in class Component
Following copied from class: java.awt.Component
Parameters:
e - the key event.
See Also:
KeyEvent, KeyListener, Component.addKeyListener(java.awt.event.KeyListener), Component.enableEvents(long)

update

public void update(Graphics g)
Just calls paint(g). This method was overridden to prevent an unneccessary call to clear the background.
Overrides:
update in class Container
Following copied from class: java.awt.Container
Parameters:
g - the specified Graphics window
See Also:
Component.update(java.awt.Graphics)

setJMenuBar

public void setJMenuBar(JMenuBar menuBar)
Sets the menubar for this applet.
Parameters:
menubar - the menubar being placed in the applet
See Also:
getJMenuBar()

getJMenuBar

public JMenuBar getJMenuBar()
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()

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
Throws:
Error - if called with rootPaneChecking true
See Also:
setRootPaneCheckingEnabled(boolean)

remove

public void remove(Component comp)
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)
By default the layout of this component may not be set, the layout of its contentPane should be set instead. For example:
 thiComponent.getContentPane().setLayout(new BorderLayout())
 
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
Throws:
Error - if called with rootPaneChecking true
See Also:
setRootPaneCheckingEnabled(boolean)

getRootPane

public JRootPane getRootPane()
Returns the rootPane object for this applet.
Specified by:
getRootPane in interface RootPaneContainer
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()
Returns the contentPane object for this applet.
Specified by:
getContentPane in interface RootPaneContainer
See Also:
setContentPane(java.awt.Container), RootPaneContainer.getContentPane()

setContentPane

public void setContentPane(Container contentPane)
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
Throws:
IllegalComponentStateException - (a runtime exception) if the content pane parameter is null
See Also:
getContentPane(), RootPaneContainer.setContentPane(java.awt.Container)

getLayeredPane

public JLayeredPane getLayeredPane()
Returns the layeredPane object for this applet.
Specified by:
getLayeredPane in interface RootPaneContainer
Throws:
IllegalComponentStateException - (a runtime exception) if the layered pane parameter is null
See Also:
setLayeredPane(javax.swing.JLayeredPane), RootPaneContainer.getLayeredPane()

setLayeredPane

public void setLayeredPane(JLayeredPane layeredPane)
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()
Returns the glassPane object for this applet.
Specified by:
getGlassPane in interface RootPaneContainer
See Also:
setGlassPane(java.awt.Component), RootPaneContainer.getGlassPane()

setGlassPane

public void setGlassPane(Component glassPane)
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()
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 Applet
Returns:
an AccessibleJApplet that serves as the AccessibleContext of this JApplet

JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Oracle and/or its affiliates, in the US and other countries.
Copyright © 1995, 2010 Oracle and/or its affiliates. All rights reserved.