«^»
2.1. APIs for producing GUIs

One of the attractive features of Java is that it has APIs for producing GUIs. One of these APIs is called the Abstract Windowing Toolkit (or AWT), and it is provided in the package java.awt. Although the AWT has been present from the start, the facilities that the Java platform provides for producing GUIs have changed with each major release of Java.

In JDK 1.0, a reasonably comprehensive set of features were provided. However, events such as mouse movements, button clicks, and window closing, had to be handled in a way which led to inefficient code, and code that was inappropriate in an object-oriented system.

In JDK 1.1, the event-handling mechanism was changed: instead, an object can register itself to handle any events on a particular component (such as a mouse, a button or a window).

With the release of the Java 2 Platform in December 1998, a new set of classes for building GUIs was introduced. These classes form what is known as the Swing API. Unlike the AWT, the code of the classes that implement the Swing API is completely written in Java. Because of this, it is easy for a programmer to add new GUI components that can be used alongside the Swing components. However, when writing programs that use the Swing API, it is still necessary to use some of the basic classes of the java.awt package.

The Swing API also has a pluggable look-and-feel. The look of a window in a Windows 95/98/NT environment is different from that in a Motif environment running on a Unix workstation. With the Swing API, you can choose the look-and-feel to be that of a particular platform, to be a platform-independent look-and-feel, or to be a look-and-feel that depends on the platform on which the program is running.

Unfortunately, during the various beta releases of the Swing API, the position of the Swing API has moved. This has been inconvenient for those people developing code (or looking at books) that use this API. Although it has previously resided at com.sun.java.swing and later at java.awt.swing, the Swing API is now in the javax.swing package.