1. Overview

The Java Foundation Classes (JFC) are a set of APIs developed to support the creation of graphical user interfaces (GUIs) and to enhance the user interactivity. Basically, the JFC is composed by the following technologies:

  • Abstract Window Toolkit (AWT): Comprises the APIs that enable the integration with the native window system, providing a basic set of graphic components and support for event handling.

  • Swing: APIs that complement the AWT to provide a more rich and complete set of graphical components, including pluggable Look-and-Feel features.

  • Java 2D: Enables the creation and manipulation of advanced 2D graphics, text and images. Includes APIs for generating output to printing devices.

  • Internationalization: Include APIs to support the development of applications that can interact with the users in their own languages and characters sets.

  • Accessibility: Provide APIs to enable the use of assistive technologies, increasing the accessibility for users with disabilities.

In this course we'll see only the two first technologies: the Abstract Window Toolkit (AWT) and the Swing.

Audio in Portuguese (Comments)

The AWT contains a set of classes for writing GUI programs, do layout managing and perform event handling. The AWT GUI components are considered "heavyweight" components, that is, they delegate to a native platform-specific peer on the host system. This have caused a lot of compatibility and performance problems, constraining the resources that could be disponibilized. Because these problems they were substituted by Swing components and won't be detailed here.

Figure 10.1. AWT Peers

AWT Peers

1.3. Swing

Swing is the main part of the JFC and was built to complement and resolve many of the AWT limitations. All the visual components are drew directly on the screen and only the containers JFrame, JDialog, JWindow, and JApplet that extend AWT components make calls to native peers. All the others components are considered "lightweight" components and have no dependency with the graphics resources of the operating system.

Although many says the Swing API was heavy and slow in the beginning, the new implementations are becoming light and fast enough, enabling the creation of Java graphical interfaces that are robust and flexible.

Figure 10.2. AWT similar components

AWT similar components

Figure 10.3. New components

New components

Figure 10.4. Converter of distances between US and metric.

Converter of distances between US and metric.

Figure 10.5. Classes in the Example Program

Classes in the Example Program

  • Create the ConversionPanels (one for metric, another for U.S.).

  • The ConversionPanel class provides a way of grouping all the controls that describe a particular set of 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).

1.4.2. The Component Hierarchy

                                                             
                              Converter
                                  |
                               JPanel
                                  |
                  ----------------------------------
                  |                                |
            ConversionPanel                  ConversionPanel 
             (metricPanel)                      (usaPanel)
                  |                                |
       -----------------------          -----------------------
       |          |          |          |          |          |         
  JTextField  JComboBox  JSlider    JTextField  JComboBox  JSlider

1.4.3. Drawing

When the Converter application draws itself, here's what happens

  1. The JFrame draws itself.

  2. The Converter object draws itself, drawing a box around its area.

  3. One of the two ConversionPanels draws itself, drawing a box around its area.

  4. The contents of the ConversionPanel -- the JTextField, JComboBox and JSlider -- draw themselves.

Audio in Portuguese