Previous | Next | Trail Map | Creating a User Interface (with Swing) | Overview of the Java UI

Other AWT Classes

The AWT contains more than components. It contains a variety of classes related to drawing and event handling. This section discusses the AWT classes that are in the java.awt package. The AWT contains two other packages -- java.awt.image and java.awt.peer -- that most programs don't have to use. Classes and interfaces in those packages are discussed where necessary elsewhere in this trail.

As you learned on the previous page, components are grouped into containers. What the previous page didn't tell you is that each container uses a layout manager to control the onscreen size and position of the components it contains. The java.awt package supplies several layout manager classes. You'll learn all about layout managers in the lesson Laying Out Components within a Container(in the Creating a User Interface trail).

The java.awt package supplies several classes to represent sizes and shapes. One example is the Dimension class, which specifies the size of a rectangular area. Another is the Insets class, which is usually used to specify how much padding should exist between the outside edges of a container and the container's display area. Shape classes include Point, Rectangle, and Polygon.

The Color class is useful for representing and manipulating colors. It defines constants for commonly used colors -- for example, Color.black. While it generally uses colors in RGB (red-green-blue) format, it also understands HSB (hue-saturation-brightness) format.

The Image class provides a way to represent image data. Applets can get Image objects for GIF and JPEG images using the Applet getImage() methods. Non-applets get images using a different helper class: Toolkit. The Toolkit class provides a platform-independent interface to the platform-dependent implementation of the AWT. Although that sounds impressive, most programs don't deal with Toolkit objects directly, except to get images. Images are loaded asynchronously -- you can have a valid Image object even if the image data hasn't been loaded yet (or doesn't even exist). Using a MediaTracker object, you can keep track of the status of the image loading. MediaTracker currently works only with images, but eventually we plan to make it work with other media types, such as sounds. Using Images(in the Creating a User Interface trail) tells you all about working with images.

For controlling the look of the text your program draws, you can use Font and FontMetrics objects. The Font class lets you get basic information about fonts and create objects representing various fonts. With a FontMetrics object, you can get detailed information about the size characteristics of a particular font. You can set the font used by a component using the Component and Graphics setFont() methods. Working with Text(in the Creating a User Interface trail) tells you more about using fonts.

Finally, the Graphics and Event classes are crucial to the AWT drawing and event handling system. A Graphics object represents a drawing context -- without a Graphics object, no program can draw to the screen. An Event object represents a user action, such as a mouse click. You'll learn more about Graphics and Event objects a little later in this overview lesson.


Previous | Next | Trail Map | Creating a User Interface (with Swing) | Overview of the Java UI