Home : Course Map : Chapter 7 : Java : Supplements :
AWT Components
JavaTech
Course Map
Chapter 7

Introduction
Event Overview
Event Processing
Button Events
  Demo 1
 Demo 2
Mouse Events
  Demo3

More Components
  Demo 4  Demo 5
  Demo 6  Demo 7

LayoutManagers-1
  Demo 8     Demo 9
  Demo 10  Demo 11
  Demo 12

LayoutManagers-2
  Demo 13  Demo 14
  Demo 15  Demo 16
  Demo 17

Inner Classes
Anonymous Class
Adapter Classes
  Demo 18  Demo 19
Frames & Menus
  Demo 20  Demo 21
Exercises

    Supplements
AWT Components
  Button
     Demo 1
  Canvas
     Demo 2
  AWT GUI Demo
     Demo 3
Swing Dialogs
JOptionPane Dialog
  Demo 1
JDialog
  Demo 2
UI Enhancement: P1
  Demo 1   Demo 2
  Demo 3

UI Enhancement: P2
  Demo 1
     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

The basic AWT framework offers a number of user interface components. As discussed in Chapter 6: Java : AWT, the AWT components, are closely bound to their peers in the windowing system on the local platform. These heavyweight components thus generally take a lowest common denominator approach for the sake of portability. However, in some cases, such as on a platform with limited memory resources, you may want to avoid using the Swing components. Here we look at some of the heavyweight AWT components.

The Component class extends Object and is the base class for the AWT (as well as for Swing components). All the visible elements of an applet or application are components of one kind or another. The Component class has a very large number of methods for dealing with all aspects of the appearance, position, size, and other properties of components. For example, the paint() and getSize() methods, which we used in several examples, come from the Component class (the Applet class inherits Component).

See the Java API specification page for the Component class to become familiar with all that it does.

The Container class objects hold groups of components. The Panel class is a commonly used container. In fact, the Applet class inherits the Panel class:

   Object <- Component <- Container <- Panel <- Applet

The add(Component a) method puts the component into the container. Since containers themselves are components, they can in turn be added to other containers. The arrangement of components within a container is determined by the layout manager to be discuss later.

The default layout manager for Panel is the FlowLayout which places the components left to right, top to bottom

In this section we provide a demonstration program to illustrate the basics of using the Button and Label components. We also use a Canvas as a drawing surface in another demonstrator.

Other AWT heavyweight components include (corresponding Swing component given in parentheses):

  • TextField & TextArea - to display text and also for text input. TextField provides a single line whereas TextArea is multi-line. (JTextField, JTextArea)
  • Choice - select a single item from this component which shows one item but will display all of them in a "dropdown" menu when clicked on. (JComboBox)
  • List -displays several items in a scrollable list. (JList)
  • Checkbox - make both checkbox and radio (only one selection allowed) buttons. (JCheckBox, JRadioButton)
  • ScrollPane - holds a component such as an image that is larger than visible area. and provides crollbars to scan the component. (JScrollPane)
  • Frame - provides a standalone window to hold components for a GUI including a menu bar with dropdown menus. (JFrame)
  • Dialog, FileDialog - popup windows to interact with the user. (JDialog, JFileChooser)
  • PopupMenu - menu that floats above the interface. (JPopupMenu)

The GUI example program uses several of these components to demonstrate building an interface in the AWT framework.

 

           Tech
Histogram UI
  Demo 1
Probablity Distrib.
  Demo 2 Demo 3
RejectionMethod
Histogram Stats
  Demo 4
Exercises

           Physics
Sim & Randomness
Custom Prob. Dist.
   Demo 1
Histogram Dist.
   Demo 2
Monte Carlo
  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.