Java Reference
In-Depth Information
Chapter 3
Graphical User Interfaces
This chapter will explain the basic components of a graphical user interface (GUI) and how to use them in Java
applications. We will begin to explore the different types of relationships between classes and document both the
classes and their relationships using the Unified Modeling Language (UML).
After finishing this chapter, you should understand:
AWT, Swing, and SWT
Getters and setters
Properties
Composition
Specialization
Inheritance
UML
After finishing this chapter, you should be able to:
Create a simple frame
Display information using labels
Generate a UML diagram
End an application
Introduction to GUI, AWT, Swing, and SWT
Let's face it, you didn't get into Java to enter commands at the command prompt and see the results in black-and-white
text. You want Java applications with a full-color GUI (graphical user interface). A GUI is comprised of components
such as frames, dialog boxes, buttons, labels, and so on. Fortunately, the JRE comes with classes that define all these
components. In RAD, a programmer can create “Visual classes” that use these GUI components or create classes that
are unique versions of these GUI components.
For instance, inside of the JRE there are two packages: java.awt (Abstract Window Toolkit) and javax.swing. Both
of these packages contain classes for frames, buttons, labels, and so on. The main difference between the two is that
the appearance of an AWT component depends on the operating system that the Java application is run on. In other
words, AWT uses the operating systems windows, buttons, and so on. Swing has its own set of components that will
look the same on all operating systems. In addition, the Swing components provide more functionality than AWT
components. However, applications using Swing components will not look the same as other applications on that
computer. In addition, because Swing does not use the operating system components, Swing applications are not
 
Search WWH ::




Custom Search