5.1.1 How the Platform Implementation of GUI Components Works

How does the platform implementation of GUI components work? This is best explained by the concrete example of creating a button. Two things are important here: the functionality of the component and the way it is actually displayed on the screen.

The generic button behavior is taken care of by the event dispatcher and the event handling methods in the Button class. The AWT contains the classes Toolkit and ButtonPeer for getting the GUI component on the screen in the style that is common for the platform (Motif-, Macintosh-, or Windows NT-style). Toolkit is an abstract class (i.e., without implementations of most methods) that describes the placement of a component in an applet: in our example, Toolkit.createButton is the name of the method for creating a button. It is actually the browser or appletviewer that implements the methods promised in the Toolkit class.

The way a button really looks like on the screen is determined by the implementation provided by the browser or appletviewer for the ButtonPeer interface. With every GUI component is associated a peer that determines the look of the component. The AWT subpackage peer contains all peers and it is the browser or appletviewer again that really implements the methods

When building up a user interface, you should not deal with the platform-specific details, but instead focus on the generic behavior and design of your interface.