All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.awt.Component
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.
getAlignmentY
.
getAlignmentY
and
getAlignmentX
.
getAlignmentX
.
getAlignmentX
.
getAlignmentY()
.
x
and y
are defined to be
relative to the coordinate system of this component.
Rectangle
object.
ColorModel
used to display
the component on the output device.
Dimension
object.
System.out
.
ComponentListener
objects.
FocusListener
objects.
MouseListener
objects.
MouseMotionListener
objects.
tm
milliseconds.
r
.
b
.
d.width
and height d.height
.
width
and height
.
b
.
public static final float TOP_ALIGNMENT
getAlignmentY()
. Specifies an
alignment to the top of the component.
public static final float CENTER_ALIGNMENT
getAlignmentY
and
getAlignmentX
. Specifies an alignment to
the center of the component
public static final float BOTTOM_ALIGNMENT
getAlignmentY
. Specifies an
alignment to the bottom of the component.
public static final float LEFT_ALIGNMENT
getAlignmentX
. Specifies an
alignment to the left side of the component.
public static final float RIGHT_ALIGNMENT
getAlignmentX
. Specifies an
alignment to the right side of the component.
protected Component()
Component
can be
extended directly to create a lightweight component that does not
utilize an opaque native window. A lightweight component must be
hosted by a native container somewhere higher up in the component
tree (for example, by a Frame
object).
public String getName()
public void setName(String name)
name
- The string that is to be this
component's name.
public Container getParent()
public ComponentPeer getPeer()
public final Object getTreeLock()
public Toolkit getToolkit()
public boolean isValid()
true
if the component is valid; false
otherwise.
public boolean isVisible()
Frame
objects.
true
if the component is visible;
false
otherwise.
public boolean isShowing()
true
if the component is showing;
false
otherwise.
public boolean isEnabled()
setEnabled
method.
true
if the component is enabled;
false
otherwise.
public void setEnabled(boolean b)
b
. An enabled component can respond to user
input and generate events. Components are enabled initially by default.
b
- If true
, this component is
enabled; otherwise this component is disabled.
public void enable()
setEnabled(boolean)
.
public void enable(boolean b)
setEnabled(boolean)
.
public void disable()
setEnabled(boolean)
.
public void setVisible(boolean b)
b
.
b
- If true
, shows this component;
otherwise, hides this component.
public void show()
setVisible(boolean)
.
public void show(boolean b)
setVisible(boolean)
.
public void hide()
setVisible(boolean)
.
public Color getForeground()
public void setForeground(Color c)
c
- The color to become this component's
foreground color.
public Color getBackground()
public void setBackground(Color c)
c
- The color to become this component's
background color.
public Font getFont()
public synchronized void setFont(Font f)
f
- The font to become this component's font.
public Locale getLocale()
public void setLocale(Locale l)
l
- The locale to become this component's locale.
public ColorModel getColorModel()
ColorModel
used to display
the component on the output device.
public Point getLocation()
Point
representing
the top-left corner of the component's bounds in the coordinate
space of the component's parent.
public Point getLocationOnScreen()
Point
representing
the top-left corner of the component's bounds in the
coordinate space of the screen.
public Point location()
getLocation()
.
public void setLocation(int x,
int y)
x
and y
parameters in the coordinate space of this component's parent.
x
- The x-coordinate of the new location's
top-left corner in the parent's coordinate space.
y
- The y-coordinate of the new location's
top-left corner in the parent's coordinate space.
public void move(int x,
int y)
setLocation(int, int)
.
public void setLocation(Point p)
p
. Point
p
is given in the parent's coordinate space.
p
- The point defining the top-left corner
of the new location, given in the coordinate space of this
component's parent.
public Dimension getSize()
Dimension
object. The height
field of the Dimension
object contains
this component's height, and the width
field of the Dimension
object contains
this component's width.
Dimension
object that indicates the
size of this component.
public Dimension size()
getSize()
.
public void setSize(int width,
int height)
width
and height
.
width
- The new width of this component in pixels.
height
- The new height of this component in pixels.
public void resize(int width,
int height)
setSize(int, int)
.
public void setSize(Dimension d)
d.width
and height d.height
.
d
- The dimension specifying the new size
of this component.
public void resize(Dimension d)
setSize(Dimension)
.
public Rectangle getBounds()
Rectangle
object. The bounds specify this
component's width, height, and location relative to
its parent.
public Rectangle bounds()
getBounds()
.
public void setBounds(int x,
int y,
int width,
int height)
x
and y
, and the
new size is specified by width
and height
.
x
- The new x-coordinate of this component.
y
- The new y-coordinate of this component.
width
- The new width
of this component.
height
- The new height
of this
component.
public void reshape(int x,
int y,
int width,
int height)
setBounds(int, int, int, int)
.
public void setBounds(Rectangle r)
r
. This component's new
position is specified by r.x
and r.y
,
and its new size is specified by r.width
and
r.height
r - The new bounding rectangle for this component.
- See Also:
- getBounds, setLocation, setLocation, setSize, setSize
public Dimension getPreferredSize()
public Dimension preferredSize()
getPreferredSize()
.
public Dimension getMinimumSize()
public Dimension minimumSize()
getMinimumSize()
.
public Dimension getMaximumSize()
public float getAlignmentX()
public float getAlignmentY()
public void doLayout()
public void layout()
doLayout()
.
public void validate()
Container
.
public void invalidate()
public Graphics getGraphics()
null
if this component is currently not on
the screen.
null
if it has none.
public FontMetrics getFontMetrics(Font font)
font
- The font for which font metrics is to be
obtained.
font
.
public synchronized void setCursor(Cursor cursor)
cursor
- One of the constants defined
by the Cursor
class.
public Cursor getCursor()
public void paint(Graphics g)
g
- The graphics context to use for painting.
public void update(Graphics g)
The AWT calls the update
method in response to a
call to repaintupdate
or paint
. You can assume that
the background is not cleared.
The update
method of Component
does the following:
- Clears this component by filling it with the background color.
- Sets the color of the graphics context to be the foreground color of this component.
- Calls this component's
paint
method to completely redraw this component.
The origin of the graphics context, its
(0
, 0
) coordinate point, is the
top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.
public void paintAll(Graphics g)
The origin of the graphics context, its
(0
, 0
) coordinate point, is the
top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.
public void repaint()
This method causes a call to this component's update
method as soon as possible.
public void repaint(long tm)
update
within tm milliseconds.
public void repaint(int x,
int y,
int width,
int height)
This method causes a call to this component's update
method as soon as possible.
public void repaint(long tm,
int x,
int y,
int width,
int height)
tm
milliseconds.
This method causes a call to this component's
update
method.
public void print(Graphics g)
The default implementation of this method calls the
paint
method.
The origin of the graphics context, its
(0
, 0
) coordinate point, is the
top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.
public void printAll(Graphics g)
The origin of the graphics context, its
(0
, 0
) coordinate point, is the
top-left corner of this component. The clipping region of the
graphics context is the bounding rectangle of this component.
public boolean imageUpdate(Image img,
int flags,
int x,
int y,
int w,
int h)
imageUpdate
method of an ImageObserver
is called when more information about an
image which had been previously requested using an asynchronous
routine such as the drawImage
method of
Graphics
becomes available.
See the definition of imageUpdate
for
more information on this method and its arguments.
The imageUpdate
method of Component
incrementally draws an image on the component as more of the bits
of the image are available.
If the system property awt.image.incrementalDraw
is missing or has the value true
, the image is
incrementally drawn, If the system property has any other value,
then the image is not drawn until it has been completely loaded.
Also, if incremental drawing is in effect, the value of the
system property awt.image.redrawrate
is interpreted
as an integer to give the maximum redraw rate, in milliseconds. If
the system property is missing or cannot be interpreted as an
integer, the redraw rate is once every 100ms.
The interpretation of the x
, y
,
width
, and height
arguments depends on
the value of the infoflags
argument.
imageUpdate
for more information.
true
if the flags indicate that the
image is completely loaded;
false
otherwise.
public Image createImage(ImageProducer producer)
public Image createImage(int width,
int height)
public boolean prepareImage(Image image,
ImageObserver observer)
Image
for which to
prepare a screen representation.
ImageObserver
object
to be notified as the image is being prepared.
true
if the image has already been fully prepared;
false
otherwise.
public boolean prepareImage(Image image,
int width,
int height,
ImageObserver observer)
The image data is downloaded asynchronously in another thread, and an appropriately scaled screen representation of the image is generated.
Image
for which to prepare a screen representation.
ImageObserver
object
to be notified as the image is being prepared.
true
if the image has already been fully prepared;
false
otherwise.
public int checkImage(Image image,
ImageObserver observer)
This method does not cause the image to begin loading. An
application must use the prepareImage
method
to force the loading of an image.
Information on the flags returned by this method can be found
with the discussion of the ImageObserver
interface.
Image
object whose status
is being checked.
ImageObserver
object to be notified as the image is being prepared.
ImageObserver
flags indicating what
information about the image is currently available.
public int checkImage(Image image,
int width,
int height,
ImageObserver observer)
This method does not cause the image to begin loading. An
application must use the prepareImage
method
to force the loading of an image.
The checkImage
method of Component
calls its peer's checkImage
method to calculate
the flags. If this component does not yet have a peer, the
component's toolkit's checkImage
method is called
instead.
Information on the flags returned by this method can be found
with the discussion of the ImageObserver
interface.
Image
object whose status
is being checked.
ImageObserver
object
to be notified as the image is being prepared.
ImageObserver
flags indicating what
information about the image is currently available.
public boolean contains(int x,
int y)
x
and y
are defined to be
relative to the coordinate system of this component.
public boolean inside(int x,
int y)
public boolean contains(Point p)
public Component getComponentAt(int x,
int y)
The locate
method of Component
simply
returns the component itself if the (x, y)
coordinate location is inside its bounding box, and null
otherwise.
null
if the location
is outside this component.
public Component locate(int x,
int y)
public Component getComponentAt(Point p)
public void deliverEvent(Event e)
dispatchEvent(AWTEvent e)
.
public final void dispatchEvent(AWTEvent e)
public boolean postEvent(Event e)
public synchronized void addComponentListener(ComponentListener l)
public synchronized void removeComponentListener(ComponentListener l)
public synchronized void addFocusListener(FocusListener l)
public synchronized void removeFocusListener(FocusListener l)
public synchronized void addKeyListener(KeyListener l)
public synchronized void removeKeyListener(KeyListener l)
public synchronized void addMouseListener(MouseListener l)
public synchronized void removeMouseListener(MouseListener l)
public synchronized void addMouseMotionListener(MouseMotionListener l)
public synchronized void removeMouseMotionListener(MouseMotionListener l)
protected final void enableEvents(long eventsToEnable)
Event types are automatically enabled when a listener for that event type is added to the component.
This method only needs to be invoked by subclasses of
Component
which desire to have the specified event
types delivered to processEvent
regardless of whether
or not a listener is registered.
protected final void disableEvents(long eventsToDisable)
protected void processEvent(AWTEvent e)
process<event type>Event
method for the given class of event.
protected void processComponentEvent(ComponentEvent e)
ComponentListener
objects.
This method is not called unless component events are enabled for this component. Component events are enabled when one of the following occurs:
ComponentListener
object is registered
via addComponentListener
.
enableEvents
.
protected void processFocusEvent(FocusEvent e)
FocusListener
objects.
This method is not called unless focus events are enabled for this component. Focus events are enabled when one of the following occurs:
FocusListener
object is registered
via addFocusListener
.
enableEvents
.
protected void processKeyEvent(KeyEvent e)
This method is not called unless key events are enabled for this component. Key events are enabled when one of the following occurs:
KeyListener
object is registered
via addKeyListener
.
enableEvents
.
protected void processMouseEvent(MouseEvent e)
MouseListener
objects.
This method is not called unless mouse events are enabled for this component. Mouse events are enabled when one of the following occurs:
MouseListener
object is registered
via addMouseListener
.
enableEvents
.
protected void processMouseMotionEvent(MouseEvent e)
MouseMotionListener
objects.
This method is not called unless mouse motion events are enabled for this component. Mouse motion events are enabled when one of the following occurs:
MouseMotionListener
object is registered
via addMouseMotionListener
.
enableEvents
.
public boolean handleEvent(Event evt)
public boolean mouseDown(Event evt,
int x,
int y)
public boolean mouseDrag(Event evt,
int x,
int y)
public boolean mouseUp(Event evt,
int x,
int y)
public boolean mouseMove(Event evt,
int x,
int y)
public boolean mouseEnter(Event evt,
int x,
int y)
public boolean mouseExit(Event evt,
int x,
int y)
public boolean keyDown(Event evt,
int key)
public boolean keyUp(Event evt,
int key)
public boolean action(Event evt,
Object what)
public void addNotify()
Container.add
, and
not by user code directly.
public void removeNotify()
Container.remove
,
and not by user code directly.
public boolean gotFocus(Event evt,
Object what)
public boolean lostFocus(Event evt,
Object what)
public boolean isFocusTraversable()
requestFocus()
, but it will not automatically
be assigned focus during tab traversal.
true
if this component is
focus-traverable; false
otherwise.
public void requestFocus()
This component's gotFocus
method is called when this
method is successful. The component must be visible
on the screen for this request to be granted
public void transferFocus()
public void nextFocus()
public synchronized void add(PopupMenu popup)
public synchronized void remove(MenuComponent popup)
protected String paramString()
public String toString()
public void list()
System.out
.
public void list(PrintStream out)
public void list(PrintStream out,
int indent)
public void list(PrintWriter out)
public void list(PrintWriter out,
int indent)
All Packages Class Hierarchy This Package Previous Next Index