Java Reference
In-Depth Information
other JFrame s, and for most frames you wouldn't want closing the frame to
quit the program.)
When we “pack” the frame, that's when the real magic happens. It kicks
off the GUI activity on a separate thread, but also packs the various pieces that
we've added to the frame, sizing them as best it can to fit into the frame, and
sizing the frame to hold all the pieces. We see little of that with our example,
which has only one label.
As an aside, pack() is inherited from awt.Window , which describes the
“magic” thus:
A component is displayable when it is connected to a native screen resource.
A component is made displayable either when it is added to a displayable
containment hierarchy or when its containment hierarchy is made dis-
playable. A containment hierarchy is made displayable when its ancestor
window is either packed or made visible.
So pack() -ing the frame connects it to a “native screen resource,” which
effectively gets the whole GUI thing going.
And now back to the business at hand.
Finally, the setVisible() call makes the window appear. Then the
main() is done. In case you're wondering, go ahead and put a
System.out.println() message after the setVisible() . It will be printed
right away. The main() has ended; the GUI activity is happening on another
thread.
16.4
S LOW , S LOW , Q UICK -Q UICK , S LOW :T HE B ASIC S WING O BJECTS
Let's take a quick look at a variety of Swing objects that you can use to build a
GUI. Like any job of craftsmanship, it helps to be familiar with your tools.
What you can build will be aided (and limited) by the tools with which you
build, and by how familiar you are with them. Here are some pieces which can
be put together to make Swing GUIs:
button
A push button to trigger actions; can contain text and/or an icon.
radio button
A group of buttons where only one value can be chosen at a time.
Search WWH ::




Custom Search