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


AWT Components

The applet on this page shows you the graphical UI components we provide. Every graphical UI component is implemented with a subclass of the AWT Component class.


Your browser doesn't understand the <APPLET> tag. Here's a picture of the window you'd see if you were using a Java-compatible browser:


Implementation Note: The applet is implemented as a button that brings up the window showing the components. The window is necessary because the program includes a menu, and menus can be used only in windows. Here, for the curious, is the source code for the window that displays the components. (The Using Components, the GUI Building Blocks(in the Creating a User Interface trail)lesson will show and explain examples of using each component.) The program has both an Applet subclass and a main() method, so it can run either as an applet or as an application. The program uses the AppletButton class to provide an applet framework for the window.

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: Sliders, Scrollbars, and Text Areas

When the basic controls aren't appropriate, you can use the Scrollbar and TextArea classes to get user input. The Scrollbar class is used for both slider and scrollbar functionality. You can see an example of sliders in The Anatomy of a GUI-Based Program. You can see scrollbars in the list and text areas of the applet on this page.

The TextArea class simply provides an area to display or allow editing of several lines of text. As you can see from the applet on this page, text areas automatically include scrollbars.

Creating Custom Components: Canvases

The Canvas class lets you write custom Components. With your Canvas subclass, you can draw custom graphics to the screen -- in a paint program, image processor, or game, for example -- and implement any kind of event handling.

Labels

Labels simply display an uneditable (by the user), unselectable line of text.

Containers: Windows and Panels

The AWT provides two types of containers, both implemented as subclasses of the 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.

Browser Note: Netscape Navigator 2.0 doesn't implement the FileDialog class, since it never allows reading or writing of files on the local file system.

Here is a picture of the FileDialog window that the Solaris Applet Viewer brings up:


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