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 SWT391the separate create-then-add semantics used in the original will not apply. Inthe next secti<strong>on</strong>, we will walk through c<strong>on</strong>verting <strong>on</strong>e of these three createmethods. For now, it is enough to know that they will be changed to be methodsthat return void (no return value) and the calls to add() may be deleted.That completes the c<strong>on</strong>versi<strong>on</strong> of main().17.3.3 Step 3: C<strong>on</strong>verting the GUI build() and init()MethodsLest you believe that this means the applicati<strong>on</strong> is ready to run, just trycompiling what you have. Got a few errors yet, d<strong>on</strong>’t we?Let’s walk through c<strong>on</strong>verting the createStatus() method and its relatedmethods. We’ll then briefly discuss c<strong>on</strong>verting the createList() andcreateButt<strong>on</strong>s() c<strong>on</strong>centrating <strong>on</strong> the details of the unique UI widgets usedin each.17.3.3.1 C<strong>on</strong>verting the GUI build() MethodIn BudgetPro, the top part of the UI is the status pane. It c<strong>on</strong>sists, basically, ofthree labels. In the original applicati<strong>on</strong>, this pane is c<strong>on</strong>structed by thecreateStatus() method. In the original, it returns a Swing Comp<strong>on</strong>ent,which is then placed by calling add() <strong>on</strong> a c<strong>on</strong>tainer managed by the caller.In SWT, Widgets must be joined to their c<strong>on</strong>tainers at c<strong>on</strong>structi<strong>on</strong>, so wemust restructure this code a little bit. We create a Group to hold our classestogether as a unit. We attach the group directly to the parent Shell by usingthe member variable frame. We set the layout manager to be RowLayout.We then populate the Group. First, we add the Up butt<strong>on</strong>, which is <strong>on</strong>lyenabled when in a subaccount. While SWT does support image butt<strong>on</strong>s, wetake the shortcut of using the SWT.ARROW style, bitwise-or’ed with the SWT.UPstyle. Next, we populate the group with our Labels.Note a change we will talk about some more below: The listener forthe Butt<strong>on</strong> object called upt<strong>on</strong> is changed. The method is renamed fromaddActi<strong>on</strong>Listener() to addSelecti<strong>on</strong>Listener(). Event handling inSWT is similar to Swing/AWT, but not identical, as we will see when we goover the rewrite of the actual event handler code a little later <strong>on</strong>.These are the <strong>on</strong>ly changes we make to this method.

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

Saved successfully!

Ooh no, something went wrong!