import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MIDlet2 extends MIDlet {
private List list;
private Command cmdOk;
private Display dis;
public MIDlet2() {
// TODO Auto-generated constructor stub
}
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 {
cmdOk=new Command("确定",Command.OK,1);
list=new List("请选择",List.EXCLUSIVE);
for(int i=0;i<10;i++)
{
list.append("列表"+i, null);
}
list.addCommand(cmdOk);
dis=Display.getDisplay(this);
list.setCommandListener(new Operater());
dis.setCurrent(list);
// TODO Auto-generated method stub
}
}
class Operater implements javax.microedition.lcdui.CommandListener
{
public void commandAction(Command c, Displayable d) {
if(c.getLabel().equals("确定"))
{
List l=(List)d;
l.setTitle( l.getString(l.getSelectedIndex()));
}
}
}
张生工作室