Override keypress method in lwuit

丶灬走出姿态 提交于 2019-12-11 22:49:54

问题


How to override keypressed method form in lwuit? if suppose user press numeric 1 from keypad how can I know that user has pressed 1? In canvas we just need to handle keypressed method. but in lwuit how to handle this method. and which listener I have to implements?


回答1:


keypressed is method in interface so you always override that methos in class

see this example

if you dont khow exact key code then print key code in

public void keyPressed(keyCode){
System.out.println(keyCode);
}

run your program, press "1" and see output




回答2:


You can override the form's keyPressed/Releaseed methods (normally you should override release!). Every focusable component has these methods as well and will receive the keyPressed/Released calls when it has focus so you can override them in component as well. The keycode you will receive for numeric/character keys is the actual character (e.g. for your case '1').

You can register global listeners for the form using key listener/game listener in the form (addKeyListener, addGameKeyListener).

Notice that LWUIT has a "game key" concept for navigation/action buttons since the values for these buttons often differ between platforms.



来源:https://stackoverflow.com/questions/5907742/override-keypress-method-in-lwuit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!