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.

392Chapter 17Other Ways: Alternatives to SwingCAUTIONIf a Composite has no layout manager, each Widget in the Compositemust have its size and positi<strong>on</strong> explicitly set, or else their sizes will default tozero, and they will all be invisible! Tremendous details <strong>on</strong> SWT layout managerclasses can be found in the article “Understanding Layouts in SWT” by CarolynMacLeod and Shantha Ramachandran <strong>on</strong> the Eclipse Web site. 1317.3.3.2 C<strong>on</strong>verting the GUI init() MethodThe setStatus() method is called whenever the data in the core modelchanges. Its job is to update the UI to reflect those changes. More specifically,it updates the status pane at the top of the UI. There are corresp<strong>on</strong>dingmethods for the list pane and the butt<strong>on</strong> pane.Oddly, there are no changes in this particular method. The purpose of thismethod is unchanged. It updates the Labels with the new numbers and checksto see if the current Account is the top level Account. If it is, the Up butt<strong>on</strong>is disabled, otherwise it is enabled.It turns out that all of the methods called <strong>on</strong> the UI classes in this methodhave the same names and purposes in Swing and SWT. D<strong>on</strong>’t assume this willbe true in the other cases.17.3.3.3 Reworking Event HandlersFinally, in the litany of c<strong>on</strong>versi<strong>on</strong>, we have to modify the event handlers. Inthis case, the <strong>on</strong>ly event of interest is when the Up butt<strong>on</strong> is pressed. Pressinga Butt<strong>on</strong> produces a Selecti<strong>on</strong> event.In SWT, there are several types of events. Generally, you specify a classthat will handle the event by calling <strong>on</strong>e of the add...Listener() methods<strong>on</strong> the Widget that you wish to process the event for. Examples of thesemethod calls include:• addSelecti<strong>on</strong>Listener()• addC<strong>on</strong>trolListener()• addFocusListener()• addHelpListener()13. http://www.eclipse.org/articles/Understanding%20Layouts/Understanding%20Layouts.htm

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

Saved successfully!

Ooh no, something went wrong!