Keyboard shortcuts and action listeners

拈花ヽ惹草 提交于 2019-12-19 09:03:30

问题


Wondering how to link a keyboard key to a JButton in netbeans, Downloaded KeyEventDemo program from oracle that lets you press a key and it tells you the keycode, Now im wondering how to implement that, working on a calculator project and I already have the ability to click on any button and have it either +,-,/,* or enter so now I am wondering how to link the 2 together, essentially I'm trying to figure out how to check which key is being pressed in a method, and then run a method depending on what they pressed! thanks for any info!


回答1:


See How to Use Key Bindings. Basically you bind a KeyStroke to an Action. The tutorial also has a section on How to Use Actions.



来源:https://stackoverflow.com/questions/6405895/keyboard-shortcuts-and-action-listeners

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