Motorola T720 Developer's Manual page 41

Hide thumbs Also See for T720:
Table of Contents

Advertisement

Coding Example
This lesson demonstrates the capabilities of one LWT UI component, the Button class.
The Button class provides a simple and effective way to add interactive buttons to your
application's interface. LWT buttons have the following features:
They can have different, descriptive labels. Within limits, a button automatically
resizes itself to accommodate the text string that makes up the label.
They can be placed on the screen using a variety of offset schemes. Such offsets
schemes are relative to the screen, or from other LWT components. If the UI is
carefully designed, these offset schemes allow the buttons to adapt to a screen of a
different size automatically.
They can be enabled or disabled under program control. A disabled button does not
respond to user events. Its appearance will also be slightly different to indicate that it
is disabled.
They can be made visible or invisible under program control. Because the user can't
interact with it, an invisible button is disabled.
They have two interactive states: normal and pressed. Each state has a different
appearance to provide visual feedback to the user. A pressed button changes
appearance and sends an actuate event to the application. The actuate event signals
the application that the operation that the button represents must be carried out.
They can be customized. Unlike most LCDUI objects, LWT component classes can
be extended to customize their appearance, or to add a unique behavior in response
to user events.
The MIDlet used for this lesson shows how to use the LWT Button class. It also shows
how to customize a button. For this lesson an example class, RoundButton, extends the
Button class to display a round button. Normally, LWT buttons are rectangular.
Let's start by seeing how LWT buttons function within a mobile application.
NOTE: If you haven't already done so, download the Button sample program from the
MOTOCODER site, then launch CodeWarrior Wireless Studio and open the Button.mcp
file.
Step 1: Build the Button project
Go to the Button directory and double-click on the project file Button.mcp. This opens the
Project window. Ensure that the Java MIDlet Debug build target is selected in the pull-
down menu. Issue the Debug command (Project | Debug) to compile and link the program
and launch the debugger. If there are no errors, the phone simulator window appears,
followed by the debugger's Thread window.
Step 2: Run the MIDlet
Issue a Run command (Project | Run) to start the program under debugger control. The
phone simulator's screen should display an array of buttons, and resemble Figure 16.
There should be three rectangular buttons, and two round buttons. One of the round
buttons should be partially off-screen.
41

Advertisement

Table of Contents
loading

Table of Contents