* The Component
class is the abstract superclass of
* the nonmenu-related Abstract Window Toolkit components. Class
* Component
can also be extended directly to create a
* lightweight component. A lightweight component is a component that is
* not associated with a native window. On the contrary, a heavyweight
* component is associated with a native window. The {@link #isLightweight()}
* method may be used to distinguish between the two kinds of the components.
*
* Lightweight and heavyweight components may be mixed in a single component * hierarchy. However, for correct operating of such a mixed hierarchy of * components, the whole hierarchy must be valid. When the hierarchy gets * invalidated, like after changing the bounds of components, or * adding/removing components to/from containers, the whole hierarchy must be * validated afterwards by means of the {@link Container#validate()} method * invoked on the top-most invalid container of the hierarchy. * *
Serializable
protocol will be saved when
* the object is stored. If an AWT object has listeners that
* aren't marked serializable, they will be dropped at
* writeObject
time. Developers will need, as always,
* to consider the implications of making an object serializable.
* One situation to watch out for is this:
* * import java.awt.*; * import java.awt.event.*; * import java.io.Serializable; * * class MyApp implements ActionListener, Serializable * { * BigObjectThatShouldNotBeSerializedWithAButton bigOne; * Button aButton = new Button(); * * MyApp() * { * // Oops, now aButton has a listener with a reference * // to bigOne! * aButton.addActionListener(this); * } * * public void actionPerformed(ActionEvent e) * { * System.out.println("Hello There"); * } * } ** In this example, serializing
aButton
by itself
* will cause MyApp
and everything it refers to
* to be serialized as well. The problem is that the listener
* is serializable by coincidence, not by design. To separate
* the decisions about MyApp
and the
* ActionListener
being serializable one can use a
* nested class, as in the following example:
* * import java.awt.*; * import java.awt.event.*; * import java.io.Serializable; * * class MyApp implements java.io.Serializable * { * BigObjectThatShouldNotBeSerializedWithAButton bigOne; * Button aButton = new Button(); * * static class MyActionListener implements ActionListener * { * public void actionPerformed(ActionEvent e) * { * System.out.println("Hello There"); * } * } * * MyApp() * { * aButton.addActionListener(new MyActionListener()); * } * } **
* Note: For more information on the paint mechanisms utilitized * by AWT and Swing, including information on how to write the most * efficient painting code, see * Painting in AWT and Swing. *
* For details on the focus subsystem, see
*
* How to Use the Focus Subsystem,
* a section in The Java Tutorial, and the
* Focus Specification
* for more information.
*
* @author Arthur van Hoff
* @author Sami Shaio
*/
public abstract class Component implements ImageObserver, MenuContainer,
Serializable
{
private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component");
private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component");
private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component");
private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component");
/**
* The peer of the component. The peer implements the component's
* behavior. The peer is set when the Component
is
* added to a container that also is a peer.
* @see #addNotify
* @see #removeNotify
*/
transient ComponentPeer peer;
/**
* The parent of the object. It may be null
* for top-level components.
* @see #getParent
*/
transient Container parent;
/**
* The AppContext
of the component. Applets/Plugin may
* change the AppContext.
*/
transient AppContext appContext;
/**
* The x position of the component in the parent's coordinate system.
*
* @serial
* @see #getLocation
*/
int x;
/**
* The y position of the component in the parent's coordinate system.
*
* @serial
* @see #getLocation
*/
int y;
/**
* The width of the component.
*
* @serial
* @see #getSize
*/
int width;
/**
* The height of the component.
*
* @serial
* @see #getSize
*/
int height;
/**
* The