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

J2ME

开发平台:

Java

  1. package commandTest;
  2. import javax.microedition.lcdui.*;
  3. import javax.microedition.midlet.*;
  4. public class commandTest extends MIDlet implements CommandListener
  5. {
  6.         private Display display;
  7.         private commandTestCanvas myCanvas;
  8.         private Command  exitCmd = new Command(" 退出", Command.SCREEN, 1);
  9.         private Command  okCmd = new Command("确定", Command.SCREEN, 1);
  10.         private Command  backCmd = new Command("后退", Command.SCREEN, 1);
  11.         public commandTest()
  12.         {
  13.          myCanvas = new commandTestCanvas();
  14.                 display = Display.getDisplay(this);
  15.                 
  16.   
  17.                 myCanvas.addCommand(okCmd);
  18.                 myCanvas.addCommand(backCmd);
  19.                 myCanvas.addCommand(exitCmd); 
  20.                 myCanvas.setCommandListener(this);
  21.         }  
  22.         public void startApp()
  23.         {
  24.                  display.setCurrent(myCanvas);
  25.         }
  26.         public void pauseApp()
  27.         {
  28.         }
  29.         public void destroyApp(boolean unconditional)
  30.         {
  31.         }
  32.         public void commandAction(Command cmd, Displayable disp) {
  33.         System.out.println("command");
  34.         if(cmd == exitCmd){
  35.         destroyApp(false);
  36.         notifyDestroyed();
  37.         }               
  38.         }
  39. }