Java Reference
In-Depth Information
the separate create-then-add semantics used in the original will not apply. In
the next section, we will walk through converting one of these three create
methods. For now, it is enough to know that they will be changed to be meth-
ods that return void (no return value) and the calls to add() may be deleted.
That completes the conversion of main() .
Step 3: Converting the GUI build() and init()
Methods
17.3.3
Lest you believe that this means the application is ready to run, just try
compiling what you have. Got a few errors yet, don't we?
Let's walk through converting the createStatus() method and its relat-
ed methods. We'll then briefly discuss converting the createList() and
createButtons() concentrating on the details of the unique UI widgets used
in each.
17.3.3.1
In BudgetPro, the top part of the UI is the status pane. It consists, basically, of
three labels. In the original application, this pane is constructed by the
createStatus() method. In the original, it returns a Swing Component ,
which is then placed by calling add() on a container managed by the caller.
In SWT, Widget s must be joined to their containers at construction , so we
must restructure this code a little bit. We create a Group to hold our classes
together as a unit. We attach the group directly to the parent Shell by using
the member variable frame . We set the layout manager to be RowLayout .
We then populate the Group . First, we add the Up button, which is only
enabled when in a subaccount. While SWT does support image buttons, we
take the shortcut of using the SWT.ARROW style, bitwise-or'ed with the SWT.UP
style. Next, we populate the group with our Label s.
Note a change we will talk about some more below: The listener for
the Button object called upton is changed. The method is renamed from
addActionListener() to addSelectionListener() . Event handling in
SWT is similar to Swing/AWT, but not identical, as we will see when we go
over the rewrite of the actual event handler code a little later on.
These are the only changes we make to this method.
Converting the GUI build() Method
Search WWH ::




Custom Search