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.
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.
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.
Create the ConversionPanel
s (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).
Converter
|
JPanel
|
----------------------------------
| |
ConversionPanel ConversionPanel
(metricPanel) (usaPanel)
| |
----------------------- -----------------------
| | | | | |
JTextField JComboBox JSlider JTextField JComboBox JSlider
When the Converter
application draws
itself, here's what happens
The JFrame
draws itself.
The Converter
object draws itself,
drawing a box around its area.
One of the two ConversionPanels
draws itself, drawing a box around its area.
The contents of the ConversionPanel
-- the JTextField
, JComboBox
and JSlider
-- draw
themselves.
Copyright © 1998-2009 Dilvan Moreira