Advanced   Java   Services
Component
Back Next Up Home

Component ist die Basisklasse für alle Klassen, deren Objekte auf dem Bildschirm dargestellt werden können. Da sich alle graphischen Swingklassen letzten Endes auch von Component ableiten ist diese Klasse nicht nur für die klassischen (alten) AWT-Komponenten wichtig. Obwohl die Klasse Component keine einzige abstrakte Methode besitzt, ist sie doch abstrakt. Component bietet über 170 Methoden an. (Falls ich mich nicht verzählt habe, sind es 206, davon sind 32 als deprecated markiert, was heißt, sie sollen nicht mehr verwendet werden). Hier ein Auszug aus diesen Methoden, geordnet nach Themen.

Konstruktor
protected Component()Constructs a new Component.
Wichtige Methoden
ReturntypName der Methode
Eventhandling
void
 
 
 
addXxxListener(XxxListener l)
Adds the specified XxxListener to receive XxxEvents from this component.
Xxx steht für Component, Focus, HierarchieBounds, Hierarchy, InputMethod, Key, Mouse, MouseMotion, MouseWheel, PropertyChange.
void
 
 
 
removeXxxListener(XxxListener l)
Removes the specified XxxListener so that it no longer receives XxxEvents from this component.
Xxx steht für Component, Focus, HierarchieBounds, Hierarchy, InputMethod, Key, Mouse, MouseMotion, MouseWheel, PropertyChange.
XxxListener[]
 
 
 
getXxxListeners()
Returns an array of all the XxxListeners registered on this component.
Xxx steht für Component, Focus, HierarchieBounds, Hierarchy, InputMethod, Key, Mouse, MouseMotion, MouseWheel, PropertyChange.
Graphik
Color
 
getBackground()
Gets the background color of this component.
void
 
setBackground(Color c)
Sets the background color of this component.
Color
 
getForeground()
Gets the foreground color of this component.
void
 
setForeground(Color c)
Sets the foreground color of this component.
Cursor
 
getCursor()
Gets the cursor set in the component.
void
 
setCursor(Cursor cursor)
Sets the cursor image to the specified cursor.
Font
 
getFont()
Gets the font of this component.
void
 
setFont(Font f)
Sets the font of this component.
FontMetrics
 
getFontMetrics(Font font)
Gets the font metrics for the specified font.
Rectangle
 
getBounds()
Gets the bounds of this component in the form of a Rectangle object.
void
 
setBounds(int x, int y, int width, int height)
Moves and resizes this component.
Dimension
 
getSize()
Returns the size of this component in the form of a Dimension object.
void
 
setSize(Dimension d)
Resizes this component so that it has width d.width and height d.height.
int
 
getHeight()
Returns the current height of this component.
int
 
getWidth()
Returns the current width of this component.
int
 
getX()
Returns the current x coordinate of the components origin.
int
 
getY()
Returns the current y coordinate of the components origin.
Point
 
getLocation()
Gets the location of this component in the form of a point specifying the component's top-left corner.
Point
 
getLocationOnScreen()
Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.
Graphics
 
getGraphics()
Creates a graphics context for this component.
GraphicsConfiguration
 
getGraphicsConfiguration()
Gets the GraphicsConfiguration associated with this Component.
void
 
update(Graphics g)
Updates this component.
void
 
paint(Graphics g)
Paints this component.
void
 
repaint()
Repaints this component.
void
 
setVisible(boolean b)
Shows or hides this component depending on the value of parameter b.
Image
Image
 
createImage(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.
Fokushandling
Container
 
getFocusCycleRootAncestor()
Returns the Container which is the focus cycle root of this Component's focus traversal cycle.
Set
 
getFocusTraversalKeys(int id)
Returns the Set of focus traversal keys for a given traversal operation for this Component.
boolean
 
getFocusTraversalKeysEnabled()
Returns whether focus traversal keys are enabled for this Component.
boolean
 
isFocusable()
Returns whether this Component can be focused.
boolean
 
 
isFocusCycleRoot(Container container)
Returns whether the specified Container is the focus cycle root of this Component's focus traversal cycle.
boolean
 
isFocusOwner()
Returns true if this Component is the focus owner.
void
 
 
requestFocus()
Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window.
boolean
 
 
requestFocusInWindow()
Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window.
void
 
setFocusable(boolean focusable)
Sets the focusable state of this Component to the specified value.
void
 
setFocusTraversalKeys(int id, Set keystrokes)
Sets the focus traversal keys for a given traversal operation for this Component.
void
 
setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)
Sets whether focus traversal keys are enabled for this Component.
void
 
transferFocus()
Transfers the focus to the next component, as though this Component were the focus owner.
void
 
transferFocusBackward()
Transfers the focus to the previous component, as though this Component were the focus owner.
void
 
transferFocusUpCycle()
Transfers the focus up one focus traversal cycle.
other
Container
 
getParent()
Gets the parent of this component.


Wie man die Methoden zum Thema Eventhandling einsetzt, findet sich in einem eigenen Kapitel über
Eventhandling.

Die Version 1.4 hat die Klasse Component um eine ganze Reihe von neuen Methoden bereichert, u.a. wurde die ganze Fokzsbehandlung neu strukturiert. Eine Auflistung der neu hinzugekommenen Methoden findet sich unter

New 1.4 methods in Component and its subclasses (Summary).

Auf das neue Fokusmanagement wird eingegangen in

Neues 1.4 FocusManagement.


Container und atomare Componenten


Aus der AWTKlassenhierarchie erfahren wir, daß es zwei Arten von Componenten gibt, Container und Nicht-Container. Container sind graphische Behälter, deren Hauptfunktion es ist, Componenten (oder selbst wieder Container) zu enthalten. Nicht-Container werden gerne auch atomare Componenten genannt. Sie können keine anderen Komponenten enthalten und müssen, um dargestellt werden zu können in irgendeinem Container liegen.

top Back Next Up Home