Java Reference
In-Depth Information
Listing 5-2. Assembling Some Item Objects on a Form Object
public class StringItemDemo extends MIDlet implements CommandListener {
private Form mainForm;
private StringItem stringItem1;
private StringItem stringItem2;
public StringItem get_stringItem1() {
if (stringItem1 == null) {
stringItem1 = new StringItem(null, "This is a simple label");
}
return stringItem1;
}
public StringItem get_stringItem2() {
if (stringItem2 == null) {
stringItem2 = new StringItem("This is the StringItem label:",
"This is the StringItem text");
stringItem2.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
}
return stringItem2;
}
public Form get_mainForm() {
if (mainForm == null) {
mainForm = new Form("String Item Demo", new Item[] {
get_stringItem1(),
get_stringItem2(),
});
}
return mainForm;
}
... more code follows ...
}
If you've been playing with NetBeans and creating user interfaces using the GUI
builder, this code should look familiar; it's essentially a cleaned-up version of the code
built by NetBeans itself. It does, however, demonstrate a common pattern for populating
a Form : as the get_mainForm method shows, you can create the display items at Form
construction time:
 
Search WWH ::




Custom Search