如何替换GameCanvs中的两个命令 [英] how to replace two comands in a GameCanvs
本文介绍了如何替换GameCanvs中的两个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我想要的类中,当用户按下暂停命令时,它将替换为恢复命令
我该怎么办?
解决方案
简单(我一直都这样做).创建两个(几乎相同)命令静态 最终命令pauseCommand = 新 Command(" ,Command.ITEM , 1 ); 静态 最终命令resumeCommand = 新命令( " ,Command.ITEM, 1 );
在启动代码中,仅将pause命令添加到可显示的内容(画布,窗体或其他内容).
在您的commandAction
例程中,输入以下内容:public void commandAction(Command cmd,Displayp){ 如果(cmd.equals(pauseCommand)){ disp.removeCommand(pauseCommand); disp.addCommand(resumeCommand); // 您要暂停的任何操作 } 其他 if (cmd.equals(resumeCommand)){ disp.removeCommand(resumeCommand); disp.addCommand(pauseCommand); // 您要恢复执行的任何操作 } }
请注意,如果您真的暂停了Midlet,则其中的resume命令将不会很有用!
彼得
固定的粘贴代码中的错字. [/edit]
hi
i have a class that extends GameCanvas,
in the class i want when user press the pause command it replace with resume command
how can i do it?
解决方案
Easy (I do it all the time). Create two (almost identical) commandsstatic final Command pauseCommand = new Command("Pause", Command.ITEM, 1); static final Command resumeCommand = new Command("Resume", Command.ITEM, 1);
In your startup code, add only the pause command to your displayable (canvas, form or whatever).
In yourcommandAction
routine, have something like this:public void commandAction(Command cmd, Displayable disp) { if (cmd.equals(pauseCommand)) { disp.removeCommand(pauseCommand); disp.addCommand(resumeCommand); // whatever you do to pause } else if (cmd.equals(resumeCommand)) { disp.removeCommand(resumeCommand); disp.addCommand(pauseCommand); // whatever you do to resume } }
Note that if you are really pausing the midlet, a resume command inside it won''t be very useful!
Peter
[edit] fixed typo in cut''n''pasted code. [/edit]
这篇关于如何替换GameCanvs中的两个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文