Java Reference
In-Depth Information
documentation.
9
You might want to use that resource along with this
lightweight tutorial to fill in the gaps and shortcuts.
It should not be too surprising that there are similarities between SWT,
AWT, and Swing. They all take different approaches to solving the same
problem, namely how to control the complexity of a graphical event-driven
application. Because the problem is the same, there can't help but be similarities
between different solutions. By now you may have deduced that the
Shell
class is an analog to the
JFrame
class, and that SWT uses a system of layout
managers not too different from Swing. If so, you are on the right track and
well on your way to using SWT.
If we had to summarize the difference in approaches between SWT and
Swing, it would be that SWT tries to provide a small number of complex
classes, and Swing tries to provide a large number of simpler classes. Obviously,
this is a generalization, but everybody generalizes. Sorry.
The
Display
is a class that provides the link to the underlying GUI sys-
tem. Think of it as an abstraction of the interface to the windowing system. In
almost all cases, an SWT application will have exactly one instance of
Display
.
The
Shell
class represents a window. This class descends from a series of
abstract parent classes, so if you look at the Javadoc for
Shell
and think it is
simple, be sure to drill down into those parent classes! We'll discuss
Shell
quite
a bit more as we go along.
17.3
P
ORTING
B
UDGET
P
RO TO
SWT
The conversion of an existing application is a complex process. Always consider
rewriting from scratch. Still, it is worthwhile to show an application converted
from Swing to SWT, because it will emphasize the relationship between
the two.
We begin with the reobjecting. Starting with the
BudgetPro
class, we
need to add an instance of the
Display
class. Then the
JFrame
becomes a
Shell
. Likewise, the
JLabel
s become
Label
s. Then . . . Wait a minute. You
don't need a blow-by-blow account. Maybe it would be simpler to show you
what SWT classes roughly correspond to the equivalent Swing classes
(Table 17.1).
9.
http://download.eclipse.org/downloads/documentation/2.0/html/plugins/
org.eclipse.platform.doc.isv/reference/api/