Overview of the Java UI |
The example program defines two classes that inherit from AWT classes. It also defines a data storing class. However, most of the objects in the program are instances of AWT classes.Classes Defined in the Example Program
The example program defines two Panel subclasses, Converter and ConversionPanel, and a simple class named Unit.The Converter class is the heart of the example program. It contains the program's main() method (which is called if the program is run as an application), as well as initialization and startup code, which is called either by the main() method or by the application that loads that program as an applet. The Converter class actually extends the Applet class (which itself extends Panel), instead of directly extending Panel. This is necessary because all applets must contain an Applet subclass. However, since the example program can also run as an application, the Converter class must behave like it extends Panel, since the Applet class provides functionality that isn't available to applications.
The ConversionPanel class provides a way of grouping all the controls that describe a particular set of distance measurements. The example program creates two ConversionPanel objects, one for metric distance measurements, and the other for U.S. distance measurements.
The Unit class provides objects that group a description (such as "Centimeters") with a multiplier that indicates the number of units per meter (0.01, for example).
AWT Objects in the Example Program
The example program uses several LayoutManagers, Containers, and Components provided by the AWT package. It also creates two Insets objects and two GridBagConstraints objects.LayoutManagers are objects that arrange the onscreen representation of Components within Containers. The example program creates three objects that conform to the LayoutManager interface: a GridLayout and two GridBagLayouts. The GridLayout manages the layout of the Components in the Converter instance. Each ConversionPanel uses a GridBagLayout object to manage its Components, and a GridBagConstraints object to specify how to lay out each Component.
Besides the Converter and ConversionPanel objects, the example program can create one more Container. Specifically, if the program is run as an application (instead of as an applet), then it creates a Frame instance (a window).
All the non-Container Components in the example program are created by ConversionPanel. Each ConversionPanel contains one instance each of the AWT Label, Choice, TextField, and Scrollbar classes.
Both the Converter and the ConversionPanel classes create Insets instances that specify the padding that should appear around their onscreen representations.
Overview of the Java UI