13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

17.3 Porting BudgetPro to SWT387We are going to walk you through c<strong>on</strong>verting <strong>on</strong>ly <strong>on</strong>e of the GUI sourcefiles for the BudgetPro applicati<strong>on</strong>. We will leave c<strong>on</strong>verting the rest as an exercisefor you. We’ll talk about some of the entertaining differences between themodels. As you shall see, there is no clear “winner” here between SWT andSwing. Almost all technical choices—SWT versus Swing, Java versus C++,Emacs versus vi, or for that matter UNIX versus Windows—are tradeoffs. Thisis no excepti<strong>on</strong>. There are things we like about SWT. For simple GUI applicati<strong>on</strong>s,we think it is easier to set up and use. We think it is easier to learn in itsentirety than Swing. Swing, <strong>on</strong> the other hand, is more complete, offeringclasses that will do more than SWT. So the best soluti<strong>on</strong> depends (as always)<strong>on</strong> your requirements.17.3.1 Step 1: C<strong>on</strong>vert the Class MembersWe are going to tackle c<strong>on</strong>verting BudgetPro.java from Swing to SWT. Inreal life, this is an exercise you are unlikely to have to carry out. You will morelikely write your GUI applicati<strong>on</strong>s from scratch. But going through the c<strong>on</strong>versi<strong>on</strong>provides a useful roadmap for talking about the architecture of SWT; itteaches 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. Removeall of the awt and swing packages. If you are using an IDE, this should flagevery single line of code that touches the GUI as an error. This can be a bighelp when you are doing a mass c<strong>on</strong>versi<strong>on</strong> like this. When you have killed allthe compile errors, you know you are well <strong>on</strong> your way to completing thec<strong>on</strong>versi<strong>on</strong>.Replace the import statements with the imports you are likely to need foryour SWT applicati<strong>on</strong>. These are:import org.eclipse.swt.*;// The static SWT class, which c<strong>on</strong>tains a number of c<strong>on</strong>stants.import org.eclipse.swt.widgets.*;// The widgets library. Almost all your display elements are here.import org.eclipse.swt.events.*; // Event handlersimport org.eclipse.swt.layout.*; // Layout managersWe will go into these families of classes in more detail as we c<strong>on</strong>vert themembers and methods of BudgetPro.java.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!