每当我尝试实施CommandListener
时,我都会收到以下消息。请让我知道我需要做什么?
Midlet不是抽象的,不会覆盖抽象方法 CommandListener中的commandAction(Command,Displayable)
package displaytest;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class Midlet extends MIDlet implements CommandListener {
private Display display = null;
private Form form;
public void startApp() {
form = new Form("Hello World");
String msg = "Hello World! DisplayTest 12";
form.addCommand(screen);
form.addCommand(ok);
form.append(msg);
display = Display.getDisplay(this);
display.setCurrent(form);
}
private Command screen, ok;
public Midlet(){
form = new Form("Command Form");
screen = new Command("SCREEN", Command.SCREEN, 1);
ok = new Command("OK", Command.OK, 4);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void okCom(){
Alert ok = new Alert("OK Command", "OK Command Executed!", null, AlertType.INFO);
ok.setTimeout(5000);
display.setCurrent(ok, form);
}
}
答案 0 :(得分:1)
您需要实现接口声明的方法,检查CommandListener
您需要实现它声明的方法如下
void commandAction(Command c, Displayable d){
// your logic
}
答案 1 :(得分:1)
您需要使类成为抽象,或覆盖抽象方法commandAction(Command,Displayable)
。