首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

点击Exit没有反应,什么原因啊该如何处理

2012-02-10 
点击Exit没有反应,什么原因啊?/** To change this template, choose Tools | Templates* and open the tem

点击Exit没有反应,什么原因啊?
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.microedition.lcdui.*;

import javax.microedition.midlet.MIDlet;

/**
 * @author Tan
 */
public class MainMidlet extends MIDlet implements CommandListener {
  private Display display; 
  private Command exitCommand = new Command("Exit", Command.ITEM, 1);
  //构造函数
  public MainMidlet(){ 
  display = Display.getDisplay(this);
   
  System.out.println("Constructor");
  }
  public void startApp() {  
  System.out.println("startApp is called.");
  Form f = new Form("HelloTest");
  f.addCommand(exitCommand); 
  display.setCurrent(f);
  }

  public void pauseApp() {
  System.out.println("pauseApp is called.");
  }

  public void destroyApp(boolean unconditional) {
  System.out.println("destroyApp is called."); 
  }
   
  public void commandAction(Command cmd, Displayable disp) {
   
  if (cmd == exitCommand) {
  try {
  destroyApp(false);
  notifyDestroyed();
  } catch (Exception e) {
  e.printStackTrace();
  }
  System.out.println("exit");
  }
  }
   
}


学做的代码,退出按钮没有用,见笑了!

[解决办法]
可能你少了注册command监听者的步骤 所以没响应

Java code
f.setCommandListener(this);
[解决办法]
确实没有添加监听器啊

热点排行