Introducing the Windowing Toolkit

   

In the previous chapter, you explored the AWT's support for graphics, fonts, colors, and images. In this chapter, you'll explore the AWT's support for GUIs. This support is manifested by way of the AWT's windowing toolkit.

The windowing toolkit is a combination of entities and code that binds these entities to the underlying windowing system. Entities include components , containers, layout managers, events, and listeners.

Components lie at the heart of a GUI. They range from buttons , labels, and text fields to lists, choices, menus , and scrollbars. By using either the mouse or keyboard, a user can interact with most of these components to accomplish useful tasks .

Containers (such as frames and panels) organize components into meaningful groups. Because containers are also components, it is possible to nest containers in other containers. This nesting process can lead to sophisticated GUI layouts (and continue until memory is exhausted).

Layout managers automatically lay out GUIs by choosing appropriate positions and sizes for their components. As a result, a GUI can look good under any windowing system and video resolution. Without layout managers, you would have to manually take care of layout tasks. Although the resulting GUI might look okay when viewed under some windowing systems/video resolutions , it would probably look awful under others. This is not your fault! Without access to every supported windowing system and video resolution, how could you be expected to properly test your GUI?

Events are fired when users interact with components and containers. Listeners register themselves with these entities to "listen" for events. When an event is fired, the windowing toolkit contacts a listener and the listener takes appropriate action. For example, suppose a user presses a button. This activity results in an event being fired. Information describing this button press event is stored in an event object. The windowing toolkit passes this object to a listener and the listener handles the event.

The relationship between the windowing toolkit's components, containers, layout managers, events, and listeners is illustrated in Figure 14.1.

Figure 14.1. The windowing toolkit relates components, containers, layout managers, events, and listeners to each other.

graphics/14fig01.gif

Over the years , the AWT's windowing toolkit has been criticized for the lackluster GUIs that it creates. Although a certain amount of criticism is justified, the windowing toolkit is able to create some nice-looking GUIs, if given a chance. By the time you reach the end of this chapter, you'll find that the windowing toolkit can meet a lot of your GUI-building needs. To give you some idea of what is possible, check out the GUI presented in Figure 14.2. This GUI was produced by the TellTime application, which is used to teach young children how to tell the time. ( TellTime 's source code is included with the rest of this book's source code ”available from this book's Web site at http://www.mcp.com.)

Figure 14.2. TellTime's GUI is a sample of the windowing toolkit's abilities .

graphics/14fig02.gif

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net