Upgrading Your AWT Programs
One of the benefits of object-oriented languages is that
you can upgrade pieces of a program without rewriting the rest. 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 JButton, JTextField, and JList can be used with the same arguments and
generate the same events as Button,
TextField, and List. Some Swing containers, like JFrame, take a bit of extra work, but not
much.
Graphical buttons are essential to modern user interfaces. Nice
monitors and cheap hardware have made icons almost a necessity. The AWT
package in Java does not directly support image buttons. You could write
an extension to support them easily enough, but why bother when Swing’s
JButton class provides a standard way
to add image buttons?
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access