帮忙看看CommmandListener哪里错了

chaoliu1024 2011-01-24 03:42:54
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener; // 提示没有导入
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Ticker;

public class CommandTicker extends MIDlet {

private Display display;
private Form f;

public CommandTicker() {
super();
}

protected void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
f = new Form("Ticker测试");
Command start = new Command("开始", Command.OK, 1);
Command stop = new Command("退出", Command.STOP, 1);
f.addCommand(start);
f.addCommand(stop);
f.setCommandListener(this); // 这里报错,好像this有问题
display.setCurrent(f);
}

protected void pauseApp() {
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}

public void commandAction(Command c, Displayable s) {
String cmd = c.getLabel();
if (cmd.equals("开始")) {
f.setTicker(new Ticker("运行中..."));
} else if (cmd.equals("退出")) {
f.setTicker(new Ticker(null));
}
}
}
...全文
31 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaoliu1024 2011-01-24
  • 打赏
  • 举报
回复
我知道哪里错了...
xiaxia421 2011-01-24
  • 打赏
  • 举报
回复
你没有实现CommandListener接口
kircheis_tree 2011-01-24
  • 打赏
  • 举报
回复
改成:
public class CommandTicker extends MIDlet implements CommandListener

你没有实现CommandListener吗。。。
xiang1115 2011-01-24
  • 打赏
  • 举报
回复
public class CommandTicker extends MIDlet {

改为
public class CommandTicker extends MIDlet implements CommandListener{

ifengshow 2011-01-24
  • 打赏
  • 举报
回复
帮看看了,但我看不出问题来

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧