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.

384Chapter 17Other Ways: Alternatives to Swingdocumentati<strong>on</strong>. 9 You might want to use that resource al<strong>on</strong>g with thislightweight 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 sameproblem, namely how to c<strong>on</strong>trol the complexity of a graphical event-drivenapplicati<strong>on</strong>. Because the problem is the same, there can’t help but be similaritiesbetween different soluti<strong>on</strong>s. By now you may have deduced that the Shellclass is an analog to the JFrame class, and that SWT uses a system of layoutmanagers not too different from Swing. If so, you are <strong>on</strong> the right track andwell <strong>on</strong> your way to using SWT.If we had to summarize the difference in approaches between SWT andSwing, it would be that SWT tries to provide a small number of complexclasses, and Swing tries to provide a large number of simpler classes. Obviously,this is a generalizati<strong>on</strong>, but everybody generalizes. Sorry.The Display is a class that provides the link to the underlying GUI system.Think of it as an abstracti<strong>on</strong> of the interface to the windowing system. Inalmost all cases, an SWT applicati<strong>on</strong> will have exactly <strong>on</strong>e instance of Display.The Shell class represents a window. This class descends from a series ofabstract parent classes, so if you look at the Javadoc for Shell and think it issimple, be sure to drill down into those parent classes! We’ll discuss Shell quitea bit more as we go al<strong>on</strong>g.17.3PORTING BUDGETPRO TO SWTThe c<strong>on</strong>versi<strong>on</strong> of an existing applicati<strong>on</strong> is a complex process. Always c<strong>on</strong>siderrewriting from scratch. Still, it is worthwhile to show an applicati<strong>on</strong> c<strong>on</strong>vertedfrom Swing to SWT, because it will emphasize the relati<strong>on</strong>ship betweenthe two.We begin with the reobjecting. Starting with the BudgetPro class, weneed to add an instance of the Display class. Then the JFrame becomes aShell. Likewise, the JLabels become Labels. Then . . . Wait a minute. Youd<strong>on</strong>’t need a blow-by-blow account. Maybe it would be simpler to show youwhat SWT classes roughly corresp<strong>on</strong>d to the equivalent Swing classes(Table 17.1).9. http://download.eclipse.org/downloads/documentati<strong>on</strong>/2.0/html/plugins/org.eclipse.platform.doc.isv/reference/api/

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

Saved successfully!

Ooh no, something went wrong!