|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
, MenuContainer
, Serializable

, Canvas
, Checkbox
, Choice
, Container
, Label
, List
, Scrollbar
, TextComponent

public abstract class Component

, MenuContainer
, Serializable

A component is an object having a graphical representation that can be displayed on the screen and that can interact with the user. Examples of components are the buttons, checkboxes, and scrollbars of a typical graphical user interface.
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 opaque window.
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 java.io.Serializable
{
BigObjectThatShouldNotBeSerializedWithAButton bigOne;
Button aButton = new Button();
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.
| Nested Class Summary | |
|---|---|
protected class |
Component.AccessibleAWTComponent
Inner class of Component used to provide default support for accessibility. |
protected class |
Component.BltBufferStrategy
Inner class for blitting offscreen surfaces to a component. |
protected class |
Component.FlipBufferStrategy
Inner class for flipping buffers on a component. |
| Field Summary | |
|---|---|
static float |
BOTTOM_ALIGNMENT
Ease-of-use constant for getAlignmentY. |
static float |
CENTER_ALIGNMENT
Ease-of-use constant for getAlignmentY and
getAlignmentX. |
static float |
LEFT_ALIGNMENT
Ease-of-use constant for getAlignmentX. |
static float |
RIGHT_ALIGNMENT
Ease-of-use constant for getAlignmentX. |
static float |
TOP_ALIGNMENT
Ease-of-use constant for getAlignmentY(). |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
protected |
Component
Constructs a new component. |
| Method Summary | |
|---|---|
boolean |
action
Deprecated. As of JDK version 1.1, should register this component as ActionListener on component which fires action events. |
void |
add
Adds the specified popup menu to the component. |
void |
addComponentListener
Adds the specified component listener to receive component events from this component. |
void |
addFocusListener
Adds the specified focus listener to receive focus events from this component when this component gains input focus. |
void |
addHierarchyBoundsListener
Adds the specified hierarchy bounds listener to receive hierarchy bounds events from this component when the hierarchy to which this container belongs changes. |
void |
addHierarchyListener
Adds the specified hierarchy listener to receive hierarchy changed events from this component when the hierarchy to which this container belongs changes. |
void |
addInputMethodListener
Adds the specified input method listener to receive input method events from this component. |
void |
addKeyListener
Adds the specified key listener to receive key events from this component. |
void |
addMouseListener
Adds the specified mouse listener to receive mouse events from this component. |
void |
addMouseMotionListener
Adds the specified mouse motion listener to receive mouse motion events from this component. |
void |
addMouseWheelListener
Adds the specified mouse wheel listener to receive mouse wheel events from this component. |
void |
addNotify
Makes this Component displayable by connecting it to a
native screen resource. |
void |
addPropertyChangeListener
Adds a PropertyChangeListener to the listener list. |
void |
addPropertyChangeListener
Adds a PropertyChangeListener to the listener list for a specific property. |
void |
applyComponentOrientation
Sets the ComponentOrientation property of this component
and all components contained within it. |
boolean |
areFocusTraversalKeysSet
Returns whether the Set of focus traversal keys for the given focus traversal operation has been explicitly defined for this Component. |
Rectangle |
bounds
Deprecated. As of JDK version 1.1, replaced by getBounds(). |
int |
checkImage
Returns the status of the construction of a screen representation of the specified image. |
int |
checkImage
Returns the status of the construction of a screen representation of the specified image. |
protected AWTEvent |
coalesceEvents
Potentially coalesce an event being posted with an existing event. |
boolean |
contains
Checks whether this component "contains" the specified point, where x and y are defined to be
relative to the coordinate system of this component. |
boolean |
contains
Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the coordinate system of this component. |
Image |
createImage
Creates an image from the specified image producer. |
Image |
createImage
Creates an off-screen drawable image to be used for double buffering. |
VolatileImage |
createVolatileImage
Creates a volatile off-screen drawable image to be used for double buffering. |
VolatileImage |
createVolatileImage
Creates a volatile off-screen drawable image, with the given capabilities. |
void |
deliverEvent
Deprecated. As of JDK version 1.1, replaced by dispatchEvent(AWTEvent e). |
void |
disable
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean). |
protected void |
disableEvents
Disables the events defined by the specified event mask parameter from being delivered to this component. |
void |
dispatchEvent
Dispatches an event to this component or one of its sub components. |
void |
doLayout
Prompts the layout manager to lay out this component. |
void |
enable
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean). |
void |
enable
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean). |
protected void |
enableEvents
Enables the events defined by the specified event mask parameter to be delivered to this component. |
void |
enableInputMethods
Enables or disables input method support for this component. |
protected void |
firePropertyChange
Support for reporting bound property changes for boolean properties. |
void |
firePropertyChange
Reports a bound property change. |
void |
firePropertyChange
Reports a bound property change. |
void |
firePropertyChange
Reports a bound property change. |
void |
firePropertyChange
Reports a bound property change. |
protected void |
firePropertyChange
Support for reporting bound property changes for integer properties. |
void |
firePropertyChange
Reports a bound property change. |
protected void |
firePropertyChange
Support for reporting bound property changes for Object properties. |
void |
firePropertyChange
Reports a bound property change. |
AccessibleContext |
getAccessibleContext
Gets the AccessibleContext associated
with this Component. |
float |
getAlignmentX
Returns the alignment along the x axis. |
float |
getAlignmentY
Returns the alignment along the y axis. |
Color |
getBackground
Gets the background color of this component. |
Rectangle |
getBounds
Gets the bounds of this component in the form of a Rectangle object. |
Rectangle |
getBounds
Stores the bounds of this component into "return value" rv and return rv. |
ColorModel |
getColorModel
Gets the instance of ColorModel used to display
the component on the output device. |
Component |
getComponentAt
Determines if this component or one of its immediate subcomponents contains the (x, y) location, and if so, returns the containing component. |
Component |
getComponentAt
Returns the component or subcomponent that contains the specified point. |
ComponentListener |
getComponentListeners
Returns an array of all the component listeners registered on this component. |
ComponentOrientation |
getComponentOrientation
Retrieves the language-sensitive orientation that is to be used to order the elements or text within this component. |
Cursor |
getCursor
Gets the cursor set in the component. |
DropTarget |
getDropTarget
Gets the DropTarget associated with this
Component. |
Container |
getFocusCycleRootAncestor |