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 package java.awt contains classes for writing programs that use a graphical user interface. For example, there is a Button class that 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. In fact, the collection of classes in java.awt is called the Abstract Windowing Toolkit.

This chapter looks at some of the GUI components that are available in the AWT, and shows how to use them in applets. This is not intended to be a complete guide to the AWT, which would take several books. Instead, I have tried to cover some of the most commonly used features.


Sections in Chapter 6:

  1. Components and Layouts
  2. Component Classes
  3. Component Events
  4. Threads and Animation

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