import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
//测试Item
public class Item_test extends MIDlet implements ItemCommandListener {
private Display display;
public Item_test(){
super();
display = Display.getDisplay(this);
}
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
Form form = new Form("Item组件测试");
StringItem si1 = new StringItem("人事部","",Item.PLAIN);
StringItem si2 = new StringItem("市场部","",Item.BUTTON);
StringItem si3 = new StringItem("财务部","",Item.HYPERLINK);
//为每个子项添加命令
si2.addCommand(new Command("进入",Command.OK,1));
si2.addCommand(new Command("退出",Command.CANCEL,1));
si3.addCommand(new Command("借款",Command.ITEM, 0));
si3.addCommand(new Command("报销",Command.ITEM,1));
si2.setItemCommandListener(this);
si2.setItemCommandListener(this);
//将每个子项添加到Form中
form.append(si1);
form.append(si2);
form.append(si3);
display.setCurrent(form);
}
//两个 参数接收:命令
public void commandAction(Command c, Item i) {
// TODO Auto-generated method stub
System.out.println("当前用户选择的标签为:"+i.getLabel()+" 命令选择标题为:"+c.getLabel());
}
}
J2ME Item组件
最新推荐文章于 2021-03-22 11:41:06 发布