/**
* Java me-list Control usage case
*/
Package com.xushouwei.cn;
Import java.io.IOException;
Import Javax.microedition.lcdui.Choice;
Import Javax.microedition.lcdui.Command;
Import Javax.microedition.lcdui.CommandListener;
Import Javax.microedition.lcdui.Display;
Import javax.microedition.lcdui.Displayable;
Import Javax.microedition.lcdui.Image;
Import javax.microedition.lcdui.List;
Import Javax.microedition.midlet.MIDlet;
Import javax.microedition.midlet.MIDletStateChangeException;
public class Listdemo extends MIDlet implements commandlistener{
Define two types of events
Private final static Command cmd_exit=new command ("EXIT", command.exit,1);
Private final static Command Cmd_back=new command ("Back", Command.back, 1);
Defining Display Objects
private display display;
Private List mainlist;
Private List execlusivelist;
Private List implicitlist;
Private List multiplelist;
Private Boolean firsttime;
Public Listdemo ()
{
Display=display.getdisplay (this);
string[] stringarray={"option A", "option B", "option C", "option D"};
Image[] Imagearray=null;
Execlusivelist=new List ("Exclusive", Choice.exclusive,stringarray, Imagearray);
Execlusivelist.addcommand (Cmd_back);
Execlusivelist.addcommand (Cmd_exit);
Execlusivelist.setcommandlistener (this);
Implicitlist=new List ("Implicit", Choice.implicit,stringarray, Imagearray);
Implicitlist.addcommand (Cmd_back);
Implicitlist.addcommand (Cmd_exit);
Implicitlist.setcommandlistener (this);
Multiplelist=new List ("multiple", Choice.multiple,stringarray, Imagearray);
Multiplelist.addcommand (Cmd_back);
Multiplelist.addcommand (Cmd_exit);
Multiplelist.setcommandlistener (this);
Firsttime=true;
}
public void Commandaction (Command C, displayable D) {
TODO auto-generated Method Stub
if (D.equals (mainlist)) {
if (C==list.select_command)
{
if (D.equals (mainlist))
{
Switch ((List) d). Getselectedindex ())
{
Case 0:
Display.setcurrent (execlusivelist);
Break
Case 1:
Display.setcurrent (implicitlist);
Break
Case 2:
Display.setcurrent (multiplelist);
Break
}
}
}
}
Else
{
if (C==cmd_back)
{
Display.setcurrent (mainlist);
}
}
if (c==cmd_exit)
{
try {
Destroyapp (FALSE);
} catch (Midletstatechangeexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Notifydestroyed ();
}
}
protected void Destroyapp (Boolean arg0) throws Midletstatechangeexception {
TODO auto-generated Method Stub
}
protected void Pauseapp () {
TODO auto-generated Method Stub
}
protected void startApp () throws Midletstatechangeexception {
TODO auto-generated Method Stub
Image[] Imagearray=null;
if (firsttime)
{
try {
Image icon=image.createimage ("Images/icon.png");
Imagearray=new Image[]{icon,icon,icon};
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
String[] stringarray={"Exclusive", "implicit", "multiple"};
Mainlist=new List ("Choose type", Choice.implicit,stringarray,imagearray);
Mainlist.addcommand (Cmd_exit);
Mainlist.setcommandlistener (this);
Display.setcurrent (mainlist);
Firsttime=false;
}
}
Use cases for Java me-list controls