javax.swing
Class JApplet

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. 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.56 01/23/03
Author:
Arnaud Weber
Field Detail

rootPane

protected JRootPane rootPane
See Also:
#getRootPane
#setRootPane

rootPaneCheckingEnabled

protected boolean rootPaneCheckingEnabled
See Also:
#isRootPaneCheckingEnabled
#setRootPaneCheckingEnabled

Constructor Detail

JApplet

public JApplet()
Creates a swing applet instance.

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

Throws:
HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
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)
Just calls paint(g). This method was overridden to prevent an unnecessary call to clear the background.

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

isRootPaneCheckingEnabled

protected boolean isRootPaneCheckingEnabled()
Returns:
true if add and setLayout should be checked
See Also:
#addImpl
#setLayout
#setRootPaneCheckingEnabled

setRootPaneCheckingEnabled

protected void setRootPaneCheckingEnabled(boolean enabled)
If true then calls to add() and setLayout() will cause an exception to be thrown.
See Also:
#addImpl
#setLayout
#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.
Throws:
Error - if called with rootPaneChecking true
See Also:
#setRootPaneCheckingEnabled

remove

public void remove(Component comp)
Removes the specified component from this container.
Parameters:
comp - the component to be removed
See Also:
#add

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:
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.
Throws:
Error - if called with rootPaneChecking true
See Also:
#setRootPaneCheckingEnabled

getRootPane

public JRootPane getRootPane()
Returns the rootPane object for this applet.
See Also:
#setRootPane
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.
See Also:
#setContentPane
RootPaneContainer#getContentPane

setContentPane

public void setContentPane(Container contentPane)
Sets the contentPane property. This method is called by the constructor.
Parameters:
contentPane - the contentPane object for this applet
Throws:
java.awt.IllegalComponentStateException - (a runtime exception) if the content pane parameter is null
See Also:
#getContentPane
RootPaneContainer#setContentPane

getLayeredPane

public JLayeredPane getLayeredPane()
Returns the layeredPane object for this applet.
Throws:
java.awt.IllegalComponentStateException - (a runtime exception) if the layered pane parameter is null
See Also:
#setLayeredPane
RootPaneContainer#getLayeredPane

setLayeredPane

public void setLayeredPane(JLayeredPane layeredPane)
Sets the layeredPane property. This method is called by the constructor.
Parameters:
layeredPane - the layeredPane object for this applet
See Also:
#getLayeredPane
RootPaneContainer#setLayeredPane

getGlassPane

public Component getGlassPane()
Returns the glassPane object for this applet.
See Also:
#setGlassPane
RootPaneContainer#getGlassPane

setGlassPane

public void setGlassPane(Component glassPane)
Sets the glassPane property. This method is called by the constructor.
Parameters:
glassPane - the glassPane object for this applet
See Also:
#getGlassPane
RootPaneContainer#setGlassPane

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.
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.
Returns:
an AccessibleJApplet that serves as the AccessibleContext of this JApplet