ItemDemo.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.*;
- public class ItemDemo extends MIDlet implements CommandListener,ItemCommandListener{
- private Form mainForm;
- private Command OK_CMD;
- private Command EXIT_CMD;
- private Command LINK_CMD;
- private Command BUTTON_CMD;
- private Display display;
- private StringItem link_stringItem;
- private StringItem button_stringItem;
- private Alert hlAlert;
- private Alert bAlert;
- public ItemDemo(){
- OK_CMD=new Command("OK",Command.OK,1);
- EXIT_CMD=new Command("EXIT",Command.EXIT,1);
- LINK_CMD=new Command("LINK",Command.ITEM,2);
- BUTTON_CMD=new Command("BUTTON",Command.ITEM,2);
- mainForm=new Form("Item演示");
- //if click hyperlink "here",display anAlert
- link_stringItem=new StringItem(null,"链接",Item.HYPERLINK);
- link_stringItem.setItemCommandListener(this);
- link_stringItem.setDefaultCommand(LINK_CMD);
- button_stringItem=new StringItem(null,"请点击按键",Item.BUTTON);
- button_stringItem.setItemCommandListener(this);
- button_stringItem.setDefaultCommand(BUTTON_CMD);
- hlAlert=new Alert("Item.HYPERLINK","请联系。。。"
- ,null,AlertType.INFO);
- bAlert=new Alert("Item.Button","您按下了按钮!"
- ,null,AlertType.INFO);
- mainForm.append("有任何问题 ,请点击");
- mainForm.append(link_stringItem);
- mainForm.append(button_stringItem);
- mainForm.addCommand(OK_CMD);
- mainForm.addCommand(EXIT_CMD);
- mainForm.setCommandListener(this);
- }
- public void startApp() {
- display=Display.getDisplay(this);
- display.setCurrent(mainForm);
- }
- public void pauseApp() {
- }
- public void destroyApp(boolean unconditional) {
- }
- public void commandAction(Command c ,Displayable d){
- if(c==EXIT_CMD){
- destroyApp(false);
- notifyDestroyed();
- }
- }
- public void commandAction(Command c,Item i){
- if(c==LINK_CMD){
- display.setCurrent(hlAlert,mainForm);
- }
- else if(c==BUTTON_CMD){
- display.setCurrent(bAlert,mainForm);
- }
- }
- }