java.awt
Class Component

java.lang.Object
  |
  +--java.awt.Component
All Implemented Interfaces:
java.awt.image.ImageObserver
Direct Known Subclasses:
Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, TextComponent

public abstract class Component
extends Object
implements java.awt.image.ImageObserver

A generic Abstract Window Toolkit component.


Field Summary
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 boolean action(Event evt, Object what)
          Called if an action occurs in the Component.
 void addNotify()
          Notifies the Component to create a peer.
 Rectangle bounds()
          Returns the current bounds of this component.
 int checkImage(Image image, java.awt.image.ImageObserver observer)
          Returns the status of the construction of a screen representation of the specified image.
 int checkImage(Image image, int width, int height, java.awt.image.ImageObserver observer)
          Returns the status of the construction of a scaled screen representation of the specified image.
 Image createImage(java.awt.image.ImageProducer producer)
          Creates an image from the specified image producer.
 Image createImage(int width, int height)
          Creates an off-screen drawable Image to be used for double buffering.
 void deliverEvent(Event e)
          Delivers an event to this component or one of its sub components.
 void disable()
          Disables a component.
 void enable()
          Enables a component.
 void enable(boolean cond)
          Conditionally enables a component.
 Color getBackground()
          Gets the background color.
 java.awt.image.ColorModel getColorModel()
          Gets the ColorModel used to display the component on the output device.
 Font getFont()
          Gets the font of the component.
 FontMetrics getFontMetrics(Font font)
          Gets the font metrics for this component.
 Color getForeground()
          Gets the foreground color.
 Graphics getGraphics()
          Gets a Graphics context for this component.
 Container getParent()
          Gets the parent of the component.
 java.awt.peer.ComponentPeer getPeer()
          Gets the peer of the component.
 Toolkit getToolkit()
          Gets the toolkit of the component.
 boolean gotFocus(Event evt, Object what)
          Indicates that this component has received the input focus.
 boolean handleEvent(Event evt)
          Handles the event.
 void hide()
          Hides the component.
 boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
          Repaints the component when the image has changed.
 boolean inside(int x, int y)
          Checks whether a specified x,y location is "inside" this Component, where x and y are defined to be relative to the coordinate system of this component.
 void invalidate()
          Invalidates the component.
 boolean isEnabled()
          Checks if this Component is enabled.
 boolean isShowing()
          Checks if this Component is showing on screen.
 boolean isValid()
          Checks if this Component is valid.
 boolean isVisible()
          Checks if this Component is visible.
 boolean keyDown(Event evt, int key)
          Called if a character is pressed.
 boolean keyUp(Event evt, int key)
          Called if a character is released.
 void layout()
          Lays out the component.
 void list()
          Prints a listing to a print stream.
 void list(PrintStream out)
          Prints a listing to the specified print out stream.
 void list(PrintStream out, int indent)
          Prints out a list, starting at the specified indention, to the specified print stream.
 Component locate(int x, int y)
          Returns the component or subcomponent that contains the x,y location.
 Point location()
          Returns the current location of this component.
 boolean lostFocus(Event evt, Object what)
          Indicates that this component has lost the input focus.
 Dimension minimumSize()
          Returns the minimum size of this component.
 boolean mouseDown(Event evt, int x, int y)
          Called if the mouse is down.
 boolean mouseDrag(Event evt, int x, int y)
          Called if the mouse is dragged (the mouse button is down).
 boolean mouseEnter(Event evt, int x, int y)
          Called when the mouse enters the component.
 boolean mouseExit(Event evt, int x, int y)
          Called when the mouse exits the component.
 boolean mouseMove(Event evt, int x, int y)
          Called if the mouse moves (the mouse button is up).
 boolean mouseUp(Event evt, int x, int y)
          Called if the mouse is up.
 void move(int x, int y)
          Moves the Component to a new location.
 void nextFocus()
          Moves the focus to the next component.
 void paint(Graphics g)
          Paints the component.
 void paintAll(Graphics g)
          Paints the component and its subcomponents.
protected  String paramString()
          Returns the parameter String of this Component.
 boolean postEvent(Event e)
          Posts an event to this component.
 Dimension preferredSize()
          Returns the preferred size of this component.
 boolean prepareImage(Image image, java.awt.image.ImageObserver observer)
          Prepares an image for rendering on this Component.
 boolean prepareImage(Image image, int width, int height, java.awt.image.ImageObserver observer)
          Prepares an image for rendering on this Component at the specified width and height.
 void print(Graphics g)
          Prints this component.
 void printAll(Graphics g)
          Prints the component and its subcomponents.
 void removeNotify()
          Notifies the Component to destroy the peer.
 void repaint()
          Repaints the component.
 void repaint(int x, int y, int width, int height)
          Repaints part of the component.
 void repaint(long tm)
          Repaints the component.
 void repaint(long tm, int x, int y, int width, int height)
          Repaints part of the component.
 void requestFocus()
          Requests the input focus.
 void reshape(int x, int y, int width, int height)
          Reshapes the Component to the specified bounding box.
 void resize(Dimension d)
          Resizes the Component to the specified dimension.
 void resize(int width, int height)
          Resizes the Component to the specified width and height.
 void setBackground(Color c)
          Sets the background color.
 void setFont(Font f)
          Sets the font of the component.
 void setForeground(Color c)
          Sets the foreground color.
 void show()
          Shows the component.
 void show(boolean cond)
          Conditionally shows the component.
 Dimension size()
          Returns the current size of this component.
 String toString()
          Returns the String representation of this Component's values.
 void update(Graphics g)
          Updates the component.
 void validate()
          Validates a component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getParent

public Container getParent()
Gets the parent of the component.


getPeer

public java.awt.peer.ComponentPeer getPeer()
Gets the peer of the component.


getToolkit

public Toolkit getToolkit()
Gets the toolkit of the component. This toolkit is used to create the peer for this component. Note that the Frame which contains a Component controls which toolkit is used so if the Component has not yet been added to a Frame or if it is later moved to a different Frame, the toolkit it uses may change.


isValid

public boolean isValid()
Checks if this Component is valid. Components are invalidated when they are first shown on the screen.

See Also:
validate(), invalidate()

isVisible

public boolean isVisible()
Checks if this Component is visible. Components are initially visible (with the exception of top level components such as Frame).

See Also:
show(), hide()

isShowing

public boolean isShowing()
Checks if this Component is showing on screen. This means that the component must be visible, and it must be in a container that is visible and showing.

See Also:
show(), hide()

isEnabled

public boolean isEnabled()
Checks if this Component is enabled. Components are initially enabled.

See Also:
enable(), disable()

location

public Point location()
Returns the current location of this component. The location will be in the parent's coordinate space.

See Also:
move(int, int)

size

public Dimension size()
Returns the current size of this component.

See Also:
resize(int, int)

bounds

public Rectangle bounds()
Returns the current bounds of this component.

See Also:
reshape(int, int, int, int)

enable

public void enable()
Enables a component.

See Also:
isEnabled(), disable()

enable

public void enable(boolean cond)
Conditionally enables a component.

Parameters:
cond - if true, enables component; disables otherwise.
See Also:
enable(), disable()

disable

public void disable()
Disables a component.

See Also:
isEnabled(), enable()

show

public void show()
Shows the component.

See Also:
isVisible(), hide()

show

public void show(boolean cond)
Conditionally shows the component.

Parameters:
cond - if true, it shows the component; hides otherwise.
See Also:
show(), hide()

hide

public void hide()
Hides the component.

See Also:
isVisible(), hide()

getForeground

public Color getForeground()
Gets the foreground color. If the component does not have a foreground color, the foreground color of its parent is returned.

See Also:
setForeground(java.awt.Color)

setForeground

public void setForeground(Color c)
Sets the foreground color.

Parameters:
c - the Color
See Also:
getForeground()

getBackground

public Color getBackground()
Gets the background color. If the component does not have a background color, the background color of its parent is returned.

See Also:
setBackground(java.awt.Color)

setBackground

public void setBackground(Color c)
Sets the background color.

Parameters:
c - the Color
See Also:
getBackground()

getFont

public Font getFont()
Gets the font of the component. If the component does not have a font, the font of its parent is returned.

See Also:
setFont(java.awt.Font)

setFont

public void setFont(Font f)
Sets the font of the component.

Parameters:
f - the font
See Also:
getFont()

getColorModel

public java.awt.image.ColorModel getColorModel()
Gets the ColorModel used to display the component on the output device.

See Also:
ColorModel

move

public void move(int x,
                 int y)
Moves the Component to a new location. The x and y coordinates are in the parent's coordinate space.

Parameters:
x - the x coordinate
y - the y coordinate
See Also:
location(), reshape(int, int, int, int)

resize

public void resize(int width,
                   int height)
Resizes the Component to the specified width and height.

Parameters:
width - the width of the component
height - the height of the component
See Also:
size(), reshape(int, int, int, int)

resize

public void resize(Dimension d)
Resizes the Component to the specified dimension.

Parameters:
d - the component dimension
See Also:
size(), reshape(int, int, int, int)

reshape

public void reshape(int x,
                    int y,
                    int width,
                    int height)
Reshapes the Component to the specified bounding box.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the component
height - the height of the component
See Also:
bounds(), move(int, int), resize(int, int)

preferredSize

public Dimension preferredSize()
Returns the preferred size of this component.

See Also:
minimumSize(), LayoutManager

minimumSize

public Dimension minimumSize()
Returns the minimum size of this component.

See Also:
preferredSize(), LayoutManager

layout

public void layout()
Lays out the component. This is usually called when the component is validated.

See Also:
validate(), LayoutManager

validate

public void validate()
Validates a component.

See Also:
invalidate(), layout(), LayoutManager

invalidate

public void invalidate()
Invalidates the component. The component and all parents above it are marked as needing to be laid out.

See Also:
validate(), layout(), LayoutManager

getGraphics

public Graphics getGraphics()
Gets a Graphics context for this component. This method will return null if the component is currently not on the screen.

See Also:
paint(java.awt.Graphics)

getFontMetrics

public FontMetrics getFontMetrics(Font font)
Gets the font metrics for this component.

Parameters:
font - the font
See Also:
getFont()

paint

public void paint(Graphics g)
Paints the component.

Parameters:
g - the specified Graphics window
See Also:
update(java.awt.Graphics)

update

public void update(Graphics g)
Updates the component. This method is called in response to a call to repaint. You can assume that the background is not cleared.

Parameters:
g - the specified Graphics window
See Also:
paint(java.awt.Graphics), repaint()

paintAll

public void paintAll(Graphics g)
Paints the component and its subcomponents.

Parameters:
g - the specified Graphics window
See Also:
paint(java.awt.Graphics)

repaint

public void repaint()
Repaints the component. This will result in a call to update as soon as possible.

See Also:
paint(java.awt.Graphics)

repaint

public void repaint(long tm)
Repaints the component. This will result in a call to update within tm milliseconds.

Parameters:
tm - maximum time in milliseconds before update
See Also:
paint(java.awt.Graphics)

repaint

public void repaint(int x,
                    int y,
                    int width,
                    int height)
Repaints part of the component. This will result in a call to update as soon as possible.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width
height - the height
See Also:
repaint()

repaint

public void repaint(long tm,
                    int x,
                    int y,
                    int width,
                    int height)
Repaints part of the component. This will result in a call to update width tm millseconds.

Parameters:
tm - maximum time in milliseconds before update
x - the x coordinate
y - the y coordinate
width - the width
height - the height
See Also:
repaint()

print

public void print(Graphics g)
Prints this component. The default implementation of this method calls paint.

Parameters:
g - the specified Graphics window
See Also:
paint(java.awt.Graphics)

printAll

public void printAll(Graphics g)
Prints the component and its subcomponents.

Parameters:
g - the specified Graphics window
See Also:
print(java.awt.Graphics)

imageUpdate

public boolean imageUpdate(Image img,
                           int flags,
                           int x,
                           int y,
                           int w,
                           int h)
Repaints the component when the image has changed.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Returns:
true if image has changed; false otherwise.

createImage

public Image createImage(java.awt.image.ImageProducer producer)
Creates an image from the specified image producer.

Parameters:
producer - the image producer

createImage

public Image createImage(int width,
                         int height)
Creates an off-screen drawable Image to be used for double buffering.

Parameters:
width - the specified width
height - the specified height

prepareImage

public boolean prepareImage(Image image,
                            java.awt.image.ImageObserver observer)
Prepares an image for rendering on this Component. The image data is downloaded asynchronously in another thread and the appropriate screen representation of the image is generated.

Parameters:
image - the Image to prepare a screen representation for
observer - the ImageObserver object to be notified as the image is being prepared
Returns:
true if the image has already been fully prepared
See Also:
ImageObserver

prepareImage

public boolean prepareImage(Image image,
                            int width,
                            int height,
                            java.awt.image.ImageObserver observer)
Prepares an image for rendering on this Component at the specified width and height. The image data is downloaded asynchronously in another thread and an appropriately scaled screen representation of the image is generated.

Parameters:
image - the Image to prepare a screen representation for
width - the width of the desired screen representation
height - the height of the desired screen representation
observer - the ImageObserver object to be notified as the image is being prepared
Returns:
true if the image has already been fully prepared
See Also:
ImageObserver

checkImage

public int checkImage(Image image,
                      java.awt.image.ImageObserver observer)
Returns the status of the construction of a screen representation of the specified image. This method does not cause the image to begin loading. Use the prepareImage method to force the loading of an image.

Parameters:
image - the Image to check the status of
observer - the ImageObserver object to be notified as the image is being prepared
Returns:
the boolean OR of the ImageObserver flags for the data that is currently available
See Also:
ImageObserver, prepareImage(java.awt.Image, java.awt.image.ImageObserver)

checkImage

public int checkImage(Image image,
                      int width,
                      int height,
                      java.awt.image.ImageObserver observer)
Returns the status of the construction of a scaled screen representation of the specified image. This method does not cause the image to begin loading, use the prepareImage method to force the loading of an image.

Parameters:
image - the Image to check the status of
width - the width of the scaled version to check the status of
height - the height of the scaled version to check the status of
observer - the ImageObserver object to be notified as the image is being prepared
Returns:
the boolean OR of the ImageObserver flags for the data that is currently available
See Also:
ImageObserver, prepareImage(java.awt.Image, java.awt.image.ImageObserver)

inside

public boolean inside(int x,
                      int y)
Checks whether a specified x,y location is "inside" this Component, where x and y are defined to be relative to the coordinate system of this component.

Parameters:
x - the x coordinate
y - the y coordinate
See Also:
locate(int, int)

locate

public Component locate(int x,
                        int y)
Returns the component or subcomponent that contains the x,y location.

Parameters:
x - the x coordinate
y - the y coordinate
See Also:
inside(int, int)

deliverEvent

public void deliverEvent(Event e)
Delivers an event to this component or one of its sub components.

Parameters:
e - the event
See Also:
handleEvent(java.awt.Event), postEvent(java.awt.Event)

postEvent

public boolean postEvent(Event e)
Posts an event to this component. This will result in a call to handleEvent. If handleEvent returns false the event is passed on to the parent of this component.

Parameters:
e - the event
See Also:
handleEvent(java.awt.Event), deliverEvent(java.awt.Event)

handleEvent

public boolean handleEvent(Event evt)
Handles the event. Returns true if the event is handled and should not be passed to the parent of this component. The default event handler calls some helper methods to make life easier on the programmer.

Parameters:
evt - the event
See Also:
mouseEnter(java.awt.Event, int, int), mouseExit(java.awt.Event, int, int), mouseMove(java.awt.Event, int, int), mouseDown(java.awt.Event, int, int), mouseDrag(java.awt.Event, int, int), mouseUp(java.awt.Event, int, int), keyDown(java.awt.Event, int), action(java.awt.Event, java.lang.Object)

mouseDown

public boolean mouseDown(Event evt,
                         int x,
                         int y)
Called if the mouse is down.

Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
See Also:
handleEvent(java.awt.Event)

mouseDrag

public boolean mouseDrag(Event evt,
                         int x,
                         int y)
Called if the mouse is dragged (the mouse button is down).

Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
See Also:
handleEvent(java.awt.Event)

mouseUp

public boolean mouseUp(Event evt,
                       int x,
                       int y)
Called if the mouse is up.

Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
See Also:
handleEvent(java.awt.Event)

mouseMove

public boolean mouseMove(Event evt,
                         int x,
                         int y)
Called if the mouse moves (the mouse button is up).

Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
See Also:
handleEvent(java.awt.Event)

mouseEnter

public boolean mouseEnter(Event evt,
                          int x,
                          int y)
Called when the mouse enters the component.

Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
See Also:
handleEvent(java.awt.Event)

mouseExit

public boolean mouseExit(Event evt,
                         int x,
                         int y)
Called when the mouse exits the component.

Parameters:
evt - the event
x - the x coordinate
y - the y coordinate
See Also:
handleEvent(java.awt.Event)

keyDown

public boolean keyDown(Event evt,
                       int key)
Called if a character is pressed.

Parameters:
evt - the event
key - the key that's pressed
See Also:
handleEvent(java.awt.Event)

keyUp

public boolean keyUp(Event evt,
                     int key)
Called if a character is released.

Parameters:
evt - the event
key - the key that's released
See Also:
handleEvent(java.awt.Event)

action

public boolean action(Event evt,
                      Object what)
Called if an action occurs in the Component.

Parameters:
evt - the event
what - the action that's occuring
See Also:
handleEvent(java.awt.Event)

addNotify

public void addNotify()
Notifies the Component to create a peer.

See Also:
getPeer(), removeNotify()

removeNotify

public void removeNotify()
Notifies the Component to destroy the peer.

See Also:
getPeer(), addNotify()

gotFocus

public boolean gotFocus(Event evt,
                        Object what)
Indicates that this component has received the input focus.

See Also:
requestFocus(), lostFocus(java.awt.Event, java.lang.Object)

lostFocus

public boolean lostFocus(Event evt,
                         Object what)
Indicates that this component has lost the input focus.

See Also:
requestFocus(), gotFocus(java.awt.Event, java.lang.Object)

requestFocus

public void requestFocus()
Requests the input focus. The gotFocus() method will be called if this method is successful.

See Also:
gotFocus(java.awt.Event, java.lang.Object)

nextFocus

public void nextFocus()
Moves the focus to the next component.

See Also:
requestFocus(), gotFocus(java.awt.Event, java.lang.Object)

paramString

protected String paramString()
Returns the parameter String of this Component.


toString

public String toString()
Returns the String representation of this Component's values.

Overrides:
toString in class Object

list

public void list()
Prints a listing to a print stream.


list

public void list(PrintStream out)
Prints a listing to the specified print out stream.

Parameters:
out - the Stream name

list

public void list(PrintStream out,
                 int indent)
Prints out a list, starting at the specified indention, to the specified print stream.

Parameters:
out - the Stream name
indent - the start of the list