StringItem sample program in J2ME

By: Kamini Viewed: 153354 times  Printer Friendly Format    


The StringItem class defines a two-part display component. StringItem objects contain a label and some immutable text. The sample J2ME program shows the pertinent parts of the StringItemDemo code. You can correlate the text in the constructor's two argument parameters with the text on the display. This is a very simple UI component.

StringItem objects give you a convenient way to associate a label with a value. You can put a String in a Form instead of using a StringItem object, but the StringItem has the advantage that its implementation ensures that the label and value strings remain together on the display.

 

 

String items are forms.
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
/**
This class demonstrates use of the StringItem MIDP UI
class.
@see javax.microedition.lcdui.StringItem
*/
public class StringItemDemo extends Form
 

implements CommandListener
{
private Command back =
new Command("Back", Command.BACK, 1);
private static Displayable instance;
private StringItem si =
new StringItem("StringItem's title",
"Immutable item text");
/**
Constructor.
*/
public StringItemDemo()
{
super("StringItem Demo");
append(si);
addCommand(back);
setCommandListener(this);
instance = this;
}
...
}

 



Most Viewed Articles (in J2ME )

Latest Articles (in J2ME)

Comment on this tutorial