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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

17.3 Porting BudgetPro to SWT389Key SWT Abstracti<strong>on</strong>sComposite is <strong>on</strong>e of the key abstracti<strong>on</strong>s in SWT. Any c<strong>on</strong>trol that mayc<strong>on</strong>tain other c<strong>on</strong>trols is a Composite.Here’s a quick rundown of the key abstract classes and interfaces inSWT, al<strong>on</strong>g with the basics of the functi<strong>on</strong>ality they embody:•A Widget is the abstract superclass of all user interface objects inSWT. At this level the methods exist that create, dispose, and dispatchevents to listeners. Every single class we use in this chapter,with the excepti<strong>on</strong> of event handlers and layout managers, is aWidget.•A C<strong>on</strong>trol is the abstract superclass of all windowed user interfaceclasses. This is almost all of the UI classes, either by direct descentor through classes such as Sash or Scrollable. All c<strong>on</strong>structorsfor C<strong>on</strong>trol classes require a Composite parent class as a c<strong>on</strong>structorargument.•A Composite is a C<strong>on</strong>trol which is capable of c<strong>on</strong>taining otherC<strong>on</strong>trols. One direct descendant of C<strong>on</strong>trol which is very similarto the Swing JPanel is Group.The relati<strong>on</strong>ships and the power of these abstracti<strong>on</strong>s will becomeclear as you work with real-life examples.(well, maybe not really skyrocket, since the import changes have alreadyproduced a lot of errors right off the bat).Finally, we remove the AbstractTableModel member. SWT has asimpler (and more limited) table functi<strong>on</strong>ality that we will discuss later.17.3.2 Step 2: C<strong>on</strong>verting the main() MethodThe main (pun unintended) changes that need to be made here include allocatingthe SWT Display, changing from instantiating a JFrame to a Shell,doing away with the Swing “look and feel” stuff (an SWT applicati<strong>on</strong> alwayslooks like a platform-native applicati<strong>on</strong>, that’s SWT’s main selling point), andreworking the c<strong>on</strong>structi<strong>on</strong> of the GUI. We’ll explain that a little bit later.For now, we take care of the simple changes. Remember that main() is astatic method, so we do not have any n<strong>on</strong>static class members available right

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

Saved successfully!

Ooh no, something went wrong!