Now that you have an overview of Swing, let’s look at a few quick Swing components you can put into your applications right now. This chapter will show you how to add images to buttons, and then go on to the more complicated, but more interesting, internal frames. We won’t belabor the theory and background. You’ll find everything we talk about now (and tons more we don’t discuss here) presented in later chapters in much greater detail. We just want to show you some of the fun stuff right away.
One of the benefits of
object-oriented languages is that you can upgrade pieces of a program
without rewriting the rest of it. While practice is never as simple
as theory, with Swing it’s close. You can use most of the Swing
components as drop-in replacements for AWT components with ease. The
components sport many fancy new features worth exploiting, but they
still maintain the functionality of the AWT components you’re
familiar with. As a general rule, you can stick a “J” in
front of your favorite AWT component and put the new class to work as
a Swing component. Constructors for components such as
JList can be used with the same arguments and
generate the same events as
List. Some Swing
JFrame, take a bit of extra work,
but not much.
One of the first steps a programmer takes when building a modern user interface for commercial or internal use is to add a ...