Chapter 6

Components and Events

MOST COMPUTERS TODAY HAVE A Graphical User Interface (GUI). With a GUI, the user interacts with the computer through windows, buttons, menus, and other components which are drawn on the screen. There are several different GUI's, for different types of computers. Although each GUI has its own look-and-feel, they all have certain features in common, and these common features make it possible to write platform-independent programs that use a GUI.

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, including the class Button. An object of type Button represents a push-button that the user can click on 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).

This chapter continues the study of GUI programming that was begun in the previous chapter by looking at a much wider selection of components, events, and layout managers. Section 4 introduces a new Java language feature, nested classes, that is useful for event-handling but that can be very useful in other contexts as well. Section 5 shows how a graphical user interface can be used in standalone applications, rather than just in applets. The final section of the chapter looks at how events were handled in the original version of Java, Java 1.0. The Java 1.0 event model can still be used in Java 1.1, and might even be more convenient than the Java 1.1 model in some cases.

Sections in Chapter 6:

  1. Components and Layouts
  2. Mouse and Keyboard Events and Listeners
  3. Standard Components and Their Events
  4. Nested Classes and Adapter Classes
  5. Frames and Dialogs
  6. The Java 1.0 Style of Event Handling

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