Java Reference
In-Depth Information
Create a Swing applet
W ith the exception of the applet examples shown in Chapter 15 , all of the programs in
this topic have been console-based. This means that they do not make use of a graphical
user interface (GUI). Although console-based programs are excellent for teaching the ba-
sics of Java and for some types of programs, such as server-side code, most real-world ap-
plications will be GUI-based. At the time of this writing, the most widely used Java GUI is
Swing.
Swing defines a collection of classes and interfaces that support a rich set of visual com-
ponents, such as buttons, text fields, scroll panes, check boxes, trees, and tables, to name a
few. Collectively, these controls can be used to construct powerful, yet easy-to-use graph-
ical interfaces. Because of its widespread use, Swing is something with which all Java pro-
grammers should be familiar. Therefore, this chapter provides an introduction to this im-
portant GUI framework.
It is important to state at the outset that Swing is a very large topic that requires an entire
book of its own. This chapter can only scratch its surface. However, the material presen-
ted here will give you a general understanding of Swing, including its history, basic con-
cepts, and design philosophy. It then introduces five commonly used Swing components:
the label, push button, text field, check box, and list. The chapter ends by showing how to
create a Swing-based applet. Although this chapter describes only a small part of Swing's
features, after completing it, you will be able to begin writing simple GUI-based programs.
You will also have a foundation upon which to continue your study of Swing.
Before moving on, it is necessary to mention that a new GUI framework called JavaFX
has recently been created for Java. JavaFX provides a powerful, streamlined, flexible ap-
proach that simplifies the creation of visually exciting GUIs. As such, JavaFX has clearly
been positioned as the platform of the future. Because of its importance, an introduction to
JavaFX is provided in Chapter 17 . Of course, Swing will continue to be in use for a long
time, in part because of the large amount of legacy code that exists for it. Therefore, both
Swing and JavaFX are likely to be part of any Java programmer's job going forward.
NOTE
For a comprehensive introduction to Swing, see my book Swing: A Beginner's Guide
(McGraw-Hill Professional, 2007).
Search WWH ::




Custom Search