Java Reference
In-Depth Information
While this may look like a lot of extra junk just to say “Hello, world,” re-
member that a GUI is not just providing output in fancy windows, but also
monitoring and responding to a wide variety of user inputs—a capability of
which we make little or no use in this example. But you can see some of this
extra capability—grab the lower left corner of the window frame and expand
and resize the window.
16.3
S TOMPIN ' AT THE S AVOY , OR T HE S WING P ARADIGM
When we say “Swing,” we generally mean the set of classes in the javax.swing
package and its subpackages (such as javax.swing.table ). The packages are
libraries of code that give you predefined classes from which you can construct
a GUI for your application. The programs you write will be written in Java,
the syntax will look like Java, but there will be a lot of creation of classes, uses
of interfaces, implementations of abstract classes, and a variety of method calls
that all deal with these Swing classes.
So what's going on with all this stuff? What can we expect to do, see,
write? In most applications that a programmer writes, it is the job of the pro-
grammer to design and write the code for the main execution path of the pro-
gram. “Yes, every program has a beginning, middle, and an end” (with apologies
to “Seymour and his frozen yoghurt stand,” from Sesame Street). But it's not
quite the same with Swing. While it does have to have a beginning, middle,
and end (these are, after all, basic Von Neumann architecture machines), the
big difference is that you do not have to write most of the control logic; it
comes as part of the Swing set.
Look at it this way. With Swing, as with other GUI toolkits, you don't
have to write code to deal with the mouse, keyboard shortcuts, or painting
characters onto a graphical screen. You don't have to write all the code
associated with a button press, because, while it seems simple enough, a button
press is really a quite complex user interaction, involving repainting of the
button's border, possibly its shading or changing its icon, coordinating that
with the mouse presses and releases, and deciding whether the releases happen
within or without the boundaries of the button—all this and more, just for a
simple button press. All this has been done for you, and packaged up into
Swing classes.
Search WWH ::




Custom Search