Previous | Next | Trail Map | Creating a User Interface | Overview of UI Elements


Graphical UI Components

This page contains an applet that shows you the graphical UI components we provide. Every graphical UI component is implemented with a subclass of the AWT Component class. If your browser isn't Java-compatible, then instead of seeing the running applet, you'll see pictures of its windows. (Here's the applet's source code.)

The Basic Controls: Buttons, Checkboxes, Choices, Lists, Menus, and Text Fields

The Button, Checkbox, Choice, List, MenuItem, and TextField classes provide basic controls. These are the most common ways that users give instructions to Java programs. When a user activates one of these controls -- by clicking a button or by pressing Return in a text field, for example -- it posts an event (ACTION_EVENT). An object that contains the control can react to the event by implementing the action() method.

Other Ways of Getting User Input: Canvases and Text Areas

When the basic controls aren't appropriate, you can use the Canvas and TextArea classes to get user input. The TextArea class simply provides an area to display or allow editing of several lines of text.

To draw custom graphics to the screen -- in a paint program, image processor, or game, for example -- create a subclass of the Canvas class.

Yet More Components: Scrollbars and Labels

The AWT provides two more handy components: scrollbars and labels. Text areas automatically have scrollbars, but you can use the Scrollbar class to make other kinds of areas scroll. Labels simply display an uneditable, unselectable line of text.

Containers: Windows and Panels

The AWT provides two types of containers, both implemented as subclasses of the Container class (which is a Component subclass). The Window subclasses -- Dialog, FileDialog, and Frame -- provide windows to contain components. Panels group components within an area of an existing window.

The example program uses a Panel to group the label and the text area, another Panel to group them with a canvas, and a third Panel to group the text field, button, checkbox, and pop-up list of choices. All these Panels are grouped by the Applet object, since the Applet class is a subclass of Panel.

The example program uses a Frame to hold the Menu and List. (Frames create normal, full-fledged windows, as opposed to the windows that Dialogs create, which are dependent on Frames and can be modal.) When the program is run as an application, then the main() method creates a Frame to hold the Applet. Finally, when you select the "File dialog..." item in the menu, the program creates a FileDialog object, which is a Dialog that can be either an Open or a Save dialog.

Here, if you don't have a Java-compatible browser, is a picture of the window that the FileDialog brings up:


Previous | Next | Trail Map | Creating a User Interface | Overview of UI Elements