Home : Course Map : Chapter 6 : Java : Supplements :
AWT User Interface Components
JavaTech
Course Map
Chapter 6

Introduction
AWT
Swing
Containers
  Demo 1
UI Components
  Demo 2
UI Layout
  Demo 3   Demo 4
Text Display
  Demo 5
Drawing
  Demo 6   Demo 7
Draw Polygons
  Demo 8   Demo 9
Colors
Text Draw 
  Demo 10
Images
  Demo 11
Exercises

    Supplements
AWT
  Demo 1
Drawing
  Demo 2
Text Drawing
  Demo 3
UI Components
  Demo 4

Java2D
Shapes & Areas
  Demo 1   Demo 2
Stroke & Paint
  Demo 3
Transforms
  Demo 4
Gradients&Textures
  Demo 5   Demo 6
Text
  Demo 7   Demo 8
     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

The previous pages discussed how to draw on the applet's panel component. However, usually panels are intended to hold user interface components that provide controls and information for a programs user.

These components include buttons, labels, textfields, menus, and several others come with the AWT packages. A Canvas component provides an area where the program can do drawing tasks such as displaying a histogram.

Note: The fundamental difference in the AWT and the Swing approach is that the AWT components are built with the operating system's GUI components (so-called peer components) whereas Swing draws its components. (Heavyweight vs Lightweight components). See Chapter 6: JFC Swing vs AWT.

The following simple applet shows how instances of three kinds of components - Label, TextField and Button - are added to the applet's panel. The Panel component is a container subclass so it can hold other components (Recall that the Applet class is a subclass of Panel.)

import java.applet.*;
import java.awt.*;

public class CompsApplet extends Applet
{
  public void init () {
   add (new Label (" A Label"));
   add (new TextField (" A TextField", 10));
   add (new Button("A Button"));
   setBackground (Color.blue);
  }
} // class
CompsApplet

How the components are arranged within the panel is determined by a LayoutManager class. The FlowLayout is the default. If you alter the size of the applet (via the tag attributes), you will see that the arrangement will vary as well, though the order of the components will follow the order in which they were added to the panel. In Chapter 7: Java : LayoutManagers we will discuss these classes in detail.

We will also discuss in Chapter 7: Java how a click on a button initates an event process that allows a program to respond to user action.

Latest update: Oct. 27, 2004

            Tech
Java Tech Graphics
Starting to Plot
  Demo 1
Drawing Panel
  Demo 2
Histogram Display

  Demo 3
Exercises

           Physics
Display Text Data
  Demo 1
Plot Data
  Demo 2
Find Max/Min
  Demo 3
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.