Abstract Windowing Toolkit

Team-Fly

AWT is a platform-independent interface that allows developers to create GUIs that run on all major platforms. AWT uses the 'common functionality/specific implementation' approach. This approach is very object-oriented in that the functionality is the superclass (high-level abstraction) and each platform's look and feel is a subclass. The common functionality/specific implementation approach allows the application to take advantage of a platform's unique GUI and makes Java applications look and feel just like other native applications. AWT also encourages innovation by allowing third parties to develop variations of GUI components.

The Java AWT uses three concepts to implement the common functionality/_platform-unique look and feel: abstract objects, toolkits, and peers. Every AWT-supported GUI element has a class, and objects of that class can be instantiated. For example, a Button object can be instantiated from the Button class-even though there is no physical display of a button-because the Button call in AWT does not represent a specific look and feel. A specific look and feel would be a Solaris button, a Macintosh button, or a Windows button. AWT GUI objects are platform-independent abstractions of a GUI in the same way that Java byte codes are platform-independent assembly language instructions for a virtual operating system display. The toolkit is the platform-specific implementation of all the GUI elements supported by AWT. Each toolkit implements the platform-specific GUI elements by creating a GUI peer.

A peer is an individual platform-specific GUI element. Because every AWT GUI object is derived from the generic AWT object called a component, every component will have a peer. The peer implements the platform-specific behavior of the AWT component; it is added to the generic AWT object when the object is added to a container that has a peer.

Accessing the Default Toolkit Properties

Let's examine some code that demonstrates toolkits and peers. The following code demonstrates how to access the default toolkit properties:

import java.awt.Toolkit; import java.awt.Dimension; class ToolkitTest {     public static void main(String args[])     {         Toolkit toolkit = Toolkit.getDefaultToolkit();         String name = System.getProperty("awt.toolkit");         System.out.println("Toolkit name: " + name);         Dimension screen = toolkit.getScreenSize();         System.out.println("Screen Dimension : " +                     screen.toString());         System.out.println("Screen Resolution (dpi): " +                     toolkit.getScreenResolution());         System.out.println("Beep.");         toolkit.beep();         System.exit(0);     } }

By compiling the code and running it in MS-DOS, you produce the following:

C:\> java ToolkitTest Toolkit name: sun.awt.windows.WToolkit Screen Dimension: java.awt.Dimension[width=800,height=600] Screen Resolution (dpi): 96 Beep.

Major Elements of AWT

AWT can be divided into six major areas.

  • Components. Components are the building blocks of GUI-based applications. GUI elements are implemented via an abstract Component class; the class's associated subclasses implement specific GUI components. For X Windows programmers, an AWT component is analogous to an X Windows widget. For Windows developers, an AWT component is analogous to a CWnd object and inherits the appropriate derived object (CButton, for example).

  • Events. A user action is translated into an Event data structure that stores the type of action and where it occurred, as well as other information. The event is then sent to the JVM (Java Virtual Machine) via the OS (Operating System). If an EventListener has been registered for this type of event, then that listener is called and may perform some action.

  • EventListeners. The Java 2 platform uses the Delegation Event Model. Under this model, classes both register for events they would like to receive and define EventListeners to receive these events. EventListeners and the new Delegation Event Model simplify and separate the handling of events from the GUI elements that generate them.

  • Containers. These are components that store other components. The most common container is the window. A panel is another very common Java AWT container whose purpose is to group other components inside a window.

  • Layout and Layout Managers. A layout determines where the components will be drawn within a container. Layout managers implement specific policies for laying out components. For example, the GridLayout class lays out added components in a tiled grid.

  • Painting and Updating. Although the prefabricated AWT components are useful, you will need to do some custom drawing in your applications. The Java AWT provides the paint(), repaint(), and update() methods to allow you to do just that.


Team-Fly


Java & BAPI Technology for SAP
Java & BAPI Technology for SAP
ISBN: 761523057
EAN: N/A
Year: 1998
Pages: 199

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