J2ME Item组件

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());
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值