点击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);
------解决方案--------------------
确实没有添加监听器啊