Motorola T720 Developer's Manual page 49

Hide thumbs Also See for T720:
Table of Contents

Advertisement

Coding Example
LWT manages this for you, and as the RoundButton code shows, you merely query these
state values as you paint the component. The LWT will issue a repaint request every time
a component's state changes.
Because of how getPreferredWidth() and getPreferredHeight()
are implemented, the button automatically sizes itself to accommodate the label's width.
Feel free to try this by editing the label in the statements that make the round buttons.
These statements can be found in the ButtonScreen's constructor.
LWT components use Component listeners to manage UI events, while LCDUI classes
use Command listeners. Can both be used in the same MIDlet? Yes, they can. The
sample MIDlet you just ran demonstrates this by using a CommandListener interface
(implemented in the DemoScreen class) to handle the Exit soft key. Meanwhile, the
ButtonScreen class implements a ComponentListerner interface, which manages the
interaction of the LWT buttons. If you look in the ButtonScreen's code, you'll see:
public void processComponentEvent(Object source, int eventType) {
} // end processComponenEvent
This is the listener for LWT component events. This method is simple in that it only
examines the source object of the event, and not the event's type. More complex LWT
classes might require you to examine the event's type. The statements that set the string
statusLabel are just code stubs that can be populated with code that actually
accomplishes something.
Now, let's see what we can do with LWT components in regards to their being visible, and
the effects of their offset schemes.
// Button #1 pressed
if (source == b1)
statusLabel= "Button #1 pressed";
// Button #2 pressed
else if (source == b2)
statusLabel= "Button #2 pressed";
// Button #3 pressed
else if (source == b3)
statusLabel= "Button #3 pressed";
// Button #4 pressed
else if (source == b4)
statusLabel= "Button #4 clicked";
// Button #5 pressed
else if (source == b5)
statusLabel= "Button #5 clicked";
49

Advertisement

Table of Contents
loading

Table of Contents