public class

JApplet

extends Applet
implements Accessible RootPaneContainer
java.lang.Object
   ↳ java.awt.Component
     ↳ java.awt.Container
       ↳ java.awt.Panel
         ↳ java.applet.Applet
           ↳ javax.swing.JApplet

Class Overview

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 its only child. The contentPane should be the parent of any children of the JApplet. As a convenience add and its variants, remove and setLayout have been overridden to forward to the contentPane as necessary. This means you can write:

       applet.add(child);
 
And the child will be added to the contentPane. 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. Refer to RootPaneContainer for details on adding, removing and setting the LayoutManager of a JApplet.

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

Warning: Swing is not thread safe. For more information see Swing's Threading Policy.

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 XMLEncoder.

Summary

Nested Classes
class JApplet.AccessibleJApplet This class implements accessibility support for the JApplet class. 
[Expand]
Inherited Constants
From class java.awt.Component
From interface java.awt.image.ImageObserver
Fields
protected AccessibleContext accessibleContext
protected JRootPane rootPane
protected boolean rootPaneCheckingEnabled If true then calls to add and setLayout will be forwarded to the contentPane.
Public Constructors
JApplet()
Creates a swing applet instance.
Public Methods
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.
Graphics getGraphics()
Creates a graphics context for this component.
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.
TransferHandler getTransferHandler()
Gets the transferHandler property.
void remove(Component comp)
Removes the specified component from the container.
void repaint(long time, int x, int y, int width, int height)
Repaints the specified rectangle of this component within time milliseconds.
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)
Sets the LayoutManager.
void setTransferHandler(TransferHandler newHandler)
Sets the transferHandler property, which is a mechanism to support transfer of data into this component.
void update(Graphics g)
Just calls paint(g).
Protected Methods
void addImpl(Component comp, Object constraints, int index)
Adds the specified child Component.
JRootPane createRootPane()
Called by the constructor methods to create the default rootPane.
boolean isRootPaneCheckingEnabled()
Returns whether calls to add and setLayout are forwarded to the contentPane.
String paramString()
Returns a string representation of this JApplet.
void setRootPane(JRootPane root)
Sets the rootPane property.
void setRootPaneCheckingEnabled(boolean enabled)
Sets whether calls to add and setLayout are forwarded to the contentPane.
[Expand]
Inherited Methods
From class java.applet.Applet
From class java.awt.Panel
From class java.awt.Container
From class java.awt.Component
From class java.lang.Object
From interface java.awt.MenuContainer
From interface java.awt.image.ImageObserver
From interface javax.accessibility.Accessible
From interface javax.swing.RootPaneContainer

Fields

protected AccessibleContext accessibleContext

protected JRootPane rootPane

protected boolean rootPaneCheckingEnabled

If true then calls to add and setLayout will be forwarded to the contentPane. This is initially false, but is set to true when the JApplet is constructed.

Public Constructors

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.

Public Methods

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

public Container getContentPane ()

Returns the contentPane object for this applet.

Returns
  • the value of the contentPane property.

public Component getGlassPane ()

Returns the glassPane object for this applet.

Returns
  • the value of the glassPane property.

public Graphics getGraphics ()

Creates a graphics context for this component. This method will return null if this component is currently not displayable.

Returns
  • a graphics context for this component, or null if it has none

public JMenuBar getJMenuBar ()

Returns the menubar set on this applet.

public JLayeredPane getLayeredPane ()

Returns the layeredPane object for this applet.

Returns
  • the value of the layeredPane property.
Throws
IllegalComponentStateException (a runtime exception) if the layered pane parameter is null

public JRootPane getRootPane ()

Returns the rootPane object for this applet.

Returns
  • this components single JRootPane child.

public TransferHandler getTransferHandler ()

Gets the transferHandler property.

Returns
  • the value of the transferHandler property

public void remove (Component comp)

Removes the specified component from the container. If comp is not the rootPane, this will forward the call to the contentPane. This will do nothing if comp is not a child of the JFrame or contentPane.

Parameters
comp the component to be removed
Throws
NullPointerException if comp is null

public void repaint (long time, int x, int y, int width, int height)

Repaints the specified rectangle of this component within time milliseconds. Refer to RepaintManager for details on how the repaint is handled.

Parameters
time maximum time in milliseconds before update
x the x coordinate
y the y coordinate
width the width
height the height
See Also

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
IllegalComponentStateException (a runtime exception) if the content pane parameter is null

public void setGlassPane (Component glassPane)

Sets the glassPane property. This method is called by the constructor.

Parameters
glassPane the glassPane object for this applet

public void setJMenuBar (JMenuBar menuBar)

Sets the menubar for this applet.

Parameters
menuBar the menubar being placed in the applet
See Also

public void setLayeredPane (JLayeredPane layeredPane)

Sets the layeredPane property. This method is called by the constructor.

Parameters
layeredPane the layeredPane object for this applet

public void setLayout (LayoutManager manager)

Sets the LayoutManager. Overridden to conditionally forward the call to the contentPane. Refer to RootPaneContainer for more information.

Parameters
manager the LayoutManager

public void setTransferHandler (TransferHandler newHandler)

Sets the transferHandler property, which is a mechanism to support transfer of data into this component. Use null if the component does not support data transfer operations.

If the system property suppressSwingDropSupport is false (the default) and the current drop target on this component is either null or not a user-set drop target, this method will change the drop target as follows: If newHandler is null it will clear the drop target. If not null it will install a new DropTarget.

Note: When used with JApplet, TransferHandler only provides data import capability, as the data export related methods are currently typed to JComponent.

Please see How to Use Drag and Drop and Data Transfer, a section in The Java Tutorial, for more information.

Parameters
newHandler the new TransferHandler

public void update (Graphics g)

Just calls paint(g). This method was overridden to prevent an unnecessary call to clear the background.

Parameters
g the specified Graphics window

Protected Methods

protected void addImpl (Component comp, Object constraints, int index)

Adds the specified child Component. This method is overridden to conditionally forward calls to the contentPane. By default, children are added to the contentPane instead of the frame, refer to RootPaneContainer for details.

Parameters
comp the component to be enhanced
constraints the constraints to be respected
index the index
Throws
IllegalArgumentException if index is invalid
IllegalArgumentException if adding the container's parent to itself
IllegalArgumentException if adding a window to a container

protected JRootPane createRootPane ()

Called by the constructor methods to create the default rootPane.

protected boolean isRootPaneCheckingEnabled ()

Returns whether calls to add and setLayout are forwarded to the contentPane.

Returns
  • true if add and setLayout are fowarded; false otherwise

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.

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

protected void setRootPaneCheckingEnabled (boolean enabled)

Sets whether calls to add and setLayout are forwarded to the contentPane.

Parameters
enabled true if add and setLayout are forwarded, false if they should operate directly on the JApplet.