J2ME Item组件
程序员文章站
2022-03-02 19:36:31
...
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 Gauge 组件测试