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.
Field Detail |
protected JRootPane rootPane
protected boolean rootPaneCheckingEnabled
Constructor Detail |
public JApplet()
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true.Method Detail |
protected JRootPane createRootPane()
public void update(Graphics g)
paint(g)
. This method was overridden to prevent an unnecessary call to clear the background.public void setJMenuBar(JMenuBar menuBar)
menuBar
- the menubar being placed in the appletpublic JMenuBar getJMenuBar()
protected boolean isRootPaneCheckingEnabled()
protected void setRootPaneCheckingEnabled(boolean enabled)
private Error createRootPaneException(String op)
"Do not use JApplet.add() use JApplet.getContentPane().add() instead"
protected void addImpl(Component comp, Object constraints, int index)
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.
Error
- if called with rootPaneChecking truepublic void remove(Component comp)
comp
- the component to be removedpublic void setLayout(LayoutManager manager)
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.
Error
- if called with rootPaneChecking truepublic JRootPane getRootPane()
protected void setRootPane(JRootPane root)
root
- the rootPane object for this appletpublic Container getContentPane()
public void setContentPane(Container contentPane)
contentPane
- the contentPane object for this appletjava.awt.IllegalComponentStateException
- (a runtime exception) if the content pane parameter is nullpublic JLayeredPane getLayeredPane()
java.awt.IllegalComponentStateException
- (a runtime exception) if the layered pane parameter is nullpublic void setLayeredPane(JLayeredPane layeredPane)
layeredPane
- the layeredPane object for this appletpublic Component getGlassPane()
public void setGlassPane(Component glassPane)
glassPane
- the glassPane object for this appletprotected String paramString()
null
.public AccessibleContext getAccessibleContext()