Java & BAPI Technology for SAP

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.


Team-Fly

Категории