Java Reference
In-Depth Information
We are going to walk you through converting only one of the GUI source
files for the BudgetPro application. We will leave converting the rest as an exer-
cise for you. We'll talk about some of the entertaining differences between the
models. As you shall see, there is no clear “winner” here between SWT and
Swing. Almost all technical choices—SWT versus Swing, Java versus C++,
Emacs versus vi , or for that matter UNIX versus Windows—are tradeoffs. This
is no exception. There are things we like about SWT. For simple GUI applica-
tions, we think it is easier to set up and use. We think it is easier to learn in its
entirety than Swing. Swing, on the other hand, is more complete, offering
classes that will do more than SWT. So the best solution depends (as always)
on your requirements.
17.3.1
We are going to tackle converting BudgetPro.java from Swing to SWT. In
real life, this is an exercise you are unlikely to have to carry out. You will more
likely write your GUI applications from scratch. But going through the conver-
sion provides a useful roadmap for talking about the architecture of SWT; it
teaches you SWT in terms of a class library with which you are already familiar.
First off, we change the packages imported at the start of the file. Remove
all of the awt and swing packages. If you are using an IDE, this should flag
every single line of code that touches the GUI as an error. This can be a big
help when you are doing a mass conversion like this. When you have killed all
the compile errors, you know you are well on your way to completing the
conversion.
Replace the import statements with the imports you are likely to need for
your SWT application. These are:
Step 1: Convert the Class Members
import org.eclipse.swt.*;
// The static SWT class, which contains a number of constants.
import org.eclipse.swt.widgets.*;
// The widgets library. Almost all your display elements are here.
import org.eclipse.swt.events.*; // Event handlers
import org.eclipse.swt.layout.*; // Layout managers
We will go into these families of classes in more detail as we convert the
members and methods of BudgetPro.java .
Search WWH ::




Custom Search