Awtandswing

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: AWT and Swing Most GUI class libraries in C++ are platform specific Different hardware capabilities Subtle differences between the "look-and-feel" of various Windowing operating systems Swing can observe various OS look-and-feel conventions Abstract Window Toolkit (AWT) is cross-platform Common functionality/specific implementation approach Toolkit -------------------------------------------------- AWT -----------|-----------Button List JVM | | Native GUI Button Peer List Peer (Windows, Mac, X) AWT GUI classes are platform-independent elements Each AWT platform-specific toolkit comes with peer class implementing platform-specific behavior of its AWT class Combining platform-independent AWT class with platform-specific peer class transforms generic, abstract windows behavior into specific, particular behavior First, create a frame. class TestPeer { Next, create a Button. TestPeer() {Attach (add) myButton to myFrame. Frame myFrameSet myFrame and myButton visible, = new Frame("my Frame"); //create window Frame Button myButton creating platform-specific peer objects. //create myButton by = new Button("my Button"); myFrame.add("Center",myButton); //put myButton inexist. Now, peer objects myFrame myFrame.setVisible(true); //button Note: getPeer() iswindow on screen appears in now "deprecated." //setVisible() creates peer objects for myFrame & myButton ComponentPeer buttonPeer = myButton.getPeer(); //now works } } Peer classes at run-time TestPeer first constructs a frame, then adds a button on the frame setVisible method creates peer objects on platform Last line now accesses myButton's peer object Peer classes are usually hidden from developers. Why? In fact, in newer versions of JDK, getPeer() method is "deprecated" Peer classes strongly discouraged for code maintenance purposes JDK 1.0 (circa 1996) JDK 1.0 went a long way to implementing platform-independent GUI library Bruce Eckel: it "produced...
View Full Document

This note was uploaded on 08/06/2008 for the course CSE 432 taught by Professor Blank during the Fall '08 term at Lehigh University .

Ask a homework question - tutors are online