ItemDemo.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.midlet.*;
  2. import javax.microedition.lcdui.*;
  3. public class ItemDemo extends MIDlet implements CommandListener,ItemCommandListener{
  4.     private Form mainForm;
  5.     private Command OK_CMD;
  6.     private Command EXIT_CMD;
  7.     private Command LINK_CMD;
  8.     private Command BUTTON_CMD;
  9.     private Display display;
  10.     private StringItem link_stringItem;
  11.     private StringItem button_stringItem;
  12.     private Alert hlAlert;
  13.     private Alert bAlert;
  14.     public ItemDemo(){
  15.         OK_CMD=new Command("OK",Command.OK,1);
  16.         EXIT_CMD=new Command("EXIT",Command.EXIT,1);
  17.         LINK_CMD=new Command("LINK",Command.ITEM,2);
  18.         BUTTON_CMD=new Command("BUTTON",Command.ITEM,2);
  19.         mainForm=new Form("Item演示");
  20.         //if click hyperlink "here",display anAlert
  21.         link_stringItem=new StringItem(null,"链接",Item.HYPERLINK);
  22.         link_stringItem.setItemCommandListener(this);
  23.         link_stringItem.setDefaultCommand(LINK_CMD);
  24.         button_stringItem=new StringItem(null,"请点击按键",Item.BUTTON);
  25.         button_stringItem.setItemCommandListener(this);
  26.         button_stringItem.setDefaultCommand(BUTTON_CMD);
  27.         hlAlert=new Alert("Item.HYPERLINK","请联系。。。"
  28.                 ,null,AlertType.INFO);
  29.         bAlert=new Alert("Item.Button","您按下了按钮!"
  30.                 ,null,AlertType.INFO);
  31.         mainForm.append("有任何问题 ,请点击");
  32.         mainForm.append(link_stringItem);
  33.         mainForm.append(button_stringItem);
  34.         mainForm.addCommand(OK_CMD);
  35.         mainForm.addCommand(EXIT_CMD);
  36.         mainForm.setCommandListener(this);
  37.     }
  38.     public void startApp() {
  39.         display=Display.getDisplay(this);
  40.         display.setCurrent(mainForm);
  41.     }
  42.     public void pauseApp() {
  43.     }
  44.     public void destroyApp(boolean unconditional) {
  45.     }
  46.     public void commandAction(Command c ,Displayable d){
  47.         if(c==EXIT_CMD){
  48.             destroyApp(false);
  49.             notifyDestroyed();
  50.         }
  51.     }
  52.     public void commandAction(Command c,Item i){
  53.         if(c==LINK_CMD){
  54.             display.setCurrent(hlAlert,mainForm);
  55.         }
  56.         else if(c==BUTTON_CMD){
  57.             display.setCurrent(bAlert,mainForm);
  58.         }
  59.     }
  60. }
  61.