日期:2014-05-20  浏览次数:20766 次

J2ME按钮基础问题
请教高手
看看下面哪里错了?已经在程序中标记出来了
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Command;


public class MIDletButton01 extends MIDlet {
private Form frm=new Form("这是一个Form");
private Display dis;
private Command cmd1=new Command("",Command.SCREEN,1);
public MIDletButton01() {

}
protected void startApp() throws MIDletStateChangeException {
dis=Display.getDisplay(this);
dis.setCurrent(frm);
frm.addCommand(cmd1);
//绑定frm和cmd1
frm.setCommandListener(this);//这一句提示有错误

public void commandAction(Command c,Displayable d){//这一句也提示有错误,好像是c和d不对
System.out.println("事件响应");
System.out.println("按钮标题为"+c.getLabel());
}
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}



}

------解决方案--------------------
1、错误1是因为这个类没实现CommandListener接口
2、错误2是因为你把commandAction声明到了另外一个方法内部了