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 MIDlet3 extends MIDlet implements CommandListener {
private List list=null;
private Command cmdOk=null;
private Display dis=null;
public MIDlet3() {
// 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.MULTIPLE);
for(int i=0;i<10;i++)
{
list.append("列表"+i, null);
}
//list.addCommand(cmdOk);
list.setCommandListener(new Operater());
dis.setCurrent(list);
// TODO Auto-generated method stub
}
public void commandAction(Command c, Displayable d) {
//Method1
int size=list.size();
for(int i=0;i<size;i++)
{
if(list.isSelected(i))
{
System.out.print(list.getString(i));
}
}
//Method 2
boolean[] Flags=new boolean[list.size()];
list.getSelectedFlags(Flags);
for(int i=0;i<list.size();i++)
{
if(Flags[i])
{
System.out.print(list.getString(i));
}
}
}
}
张生工作室