Java Reference
In-Depth Information
The java.awt.Component interface manages several different things:
• The attributes of a component, such as a component's position, font, visibility,
opacity, and so forth
• Event handling for the component; these methods comprise a deprecated set of
methods now replaced with the listener model I discuss in the “Handling AWT
Events” section later in this chapter
• Methods to support drawing the component
• Methods that manage focus and indicate which component has focus
As you have already seen, AWT components can come in two flavors: heavyweight
and lightweight. Heavyweight components are proxy interfaces to a peer object in the
native window toolkit; for example, if the java.awt.Button class has a native component
corresponding to the button, there will be a peer class somewhere that encapsulates
the interface to the native button. Lightweight components, on the other hand, have no
corresponding tangible entity in the native window toolkit; the Java environment renders
them on the fly. Although not a requirement, it's likely that if you encounter the AWT on a
PP-compliant device, the AWT will implement an interface to heavyweight components.
Heavyweight components have an advantage in that an application developed with
heavyweight components can generally match the look and feel of the native platform,
because the controls used by the heavyweight component toolkit are the same controls
as those provided by the underlying platform. However, the implementation of the
classes that bridge the AWT with the underlying platform can consume valuable heap
and ROM space, which is why not all profiles for the CDC include heavyweight components.
When working with components, it's a good idea to avoid mixing lightweight
and heavyweight components, due to limitations both in the AWT and the underlying
platform. Lightweight components—including those in the AGUI, which I discuss later
in this chapter's “Developing User Interfaces with the AGUI” section—have support for
transparent regions, unlike a heavyweight component. Among other things, this means
that heavyweight components occlude what's behind them and can only appear rec-
tangular. Moreover, when heavyweight and lightweight components intersect, the
heavyweight component is always on top, regardless of Z-order. Finally, a heavyweight
object consumes any mouse events that fall on it; a lightweight component passes
events on to its parent container.
Handling AWT Events
With the AWT, you handle events by overriding specific methods that receive events from
the window toolkit. You can do this in one of two ways: by intercepting the low-level
events that are passed to a component, or by registering listeners for high-level events.
 
Search WWH ::




Custom Search