问题描述
想知道如何将键盘键链接到netbeans中的JButton,从oracle下载的KeyEventDemo程序可以让您按一个键并告诉您键码,现在我想知道如何实现它,在计算器项目上工作,我已经能够单击任何按钮并将其设置为,,,或,所以现在我想知道如何将2链接在一起,从本质上讲,我试图弄清楚如何检查方法中按了哪个键,然后根据所按的方法运行一个方法!感谢您提供任何信息!
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 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!
推荐答案
请参见如何使用键绑定.基本上,您将KeyStroke绑定到Action.本教程还包含有关如何使用动作的部分.
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.
这篇关于键盘快捷键和动作监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!