
j2me中的Displayable问题
publicclassTranslateCanvasextendsCanvasimplementsCommandListener{privateTextFieldtfMs...
public class TranslateCanvas extends Canvas implements CommandListener{
private TextField tfMsg=new TextField("英汉互译","",20,TextField.ANY);
private Form form=new Form("英汉互译");
private Command cmdQuery=new Command("查询",Command.SCREEN,1);
private Command cmdHelp=new Command("帮助",Command.HELP,1);
private Command cmdExit=new Command("退出",Command.EXIT,1);
private TranslateMIDlet tm;
private int type=0;//默认为0,英译汉,为1代表汉译英
public TranslateCanvas(TranslateMIDlet tm) {
this.tm=tm;
form.append(tfMsg);
form.addCommand(cmdQuery);
form.addCommand(cmdHelp);
form.addCommand(cmdExit);
this.setCommandListener(this);
}
protected void paint(Graphics g) {
//由于要从控制器得到页面,但放在构建器控制器还未创建
tm.getDisplay().setCurrent(form);
}
public void commandAction(Command c, Displayable arg1) {
//问题来了,不知道为什么按键没有反映了
if(cmdHelp==c)
{//触发
tm.changeInterface("welcome");
}
}
} 展开
private TextField tfMsg=new TextField("英汉互译","",20,TextField.ANY);
private Form form=new Form("英汉互译");
private Command cmdQuery=new Command("查询",Command.SCREEN,1);
private Command cmdHelp=new Command("帮助",Command.HELP,1);
private Command cmdExit=new Command("退出",Command.EXIT,1);
private TranslateMIDlet tm;
private int type=0;//默认为0,英译汉,为1代表汉译英
public TranslateCanvas(TranslateMIDlet tm) {
this.tm=tm;
form.append(tfMsg);
form.addCommand(cmdQuery);
form.addCommand(cmdHelp);
form.addCommand(cmdExit);
this.setCommandListener(this);
}
protected void paint(Graphics g) {
//由于要从控制器得到页面,但放在构建器控制器还未创建
tm.getDisplay().setCurrent(form);
}
public void commandAction(Command c, Displayable arg1) {
//问题来了,不知道为什么按键没有反映了
if(cmdHelp==c)
{//触发
tm.changeInterface("welcome");
}
}
} 展开
1个回答
展开全部
this.setCommandListener(this);
改成
cmdQuery.setCommandListener(this);
cmdHelp.setCommandListener(this);
cmdExit.setCommandListener(this);
改成
cmdQuery.setCommandListener(this);
cmdHelp.setCommandListener(this);
cmdExit.setCommandListener(this);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询