New to Java? We'll help you get started with our revised beginner's tutorial, or our free online textbook.


Get the latest Java books
h t t p : / /w w w . j a v a c o f f e e b r e a k . c o m /

Java Coffee Break

Chapter 7

Advanced GUI Programming


THE JAVA PACKAGES java.awt and java.awt.event contain classes for writing programs that use a graphical user interface. The previous chapter introduced several of these classes, such as the class Button. An object of type Button represents a push-button that the user can click to perform some action. When the programmer creates an instance of this class, it will appear on the screen as a button appropriate to the platform on which the program is running. Even though the button will appear different on different platforms, its "logical" or "abstract" behavior will be the same. The Java programmer only has to worry about this abstract behavior; the platform-dependent details are left to the Java implementation on each platform. This is why the Java GUI system is called the Abstract Windowing Toolkit (AWT).

In this chapter, we'll take a more detailed look at using the AWT for graphical user interface programming, starting with some advanced features of the Graphics class. We'll cover a number of new layout managers, component classes, and event types, and we'll see how to open independent windows and dialog boxes on the screen. Two new features of Java, threads and nested classes, will be introduced. Both of these features are useful in many applications besides GUI programming.

This textbook is based on Java 1.1. A newer version, Java 1.2, builds on Java 1.1 by adding a large number of new standard classes. In particular, Java 1.1 introduced a new set of user interface components called Swing, as a supplement to the AWT. Java 1.2, together with a few optional features, is sometimes referred to as Java 2 or Java Platform 2. The last section of this Chapter is a brief survey of Swing and Java 2.

The material in this chapter will be used in a number of examples and programming exercises in future chapters. Aside from that, the material in this chapter is not a prerequisite the rest of this textbook.


Contents Chapter 7:


[ First Section | Next Chapter | Previous Chapter | Main Index ]