简体   繁体   English

键盘快捷键和动作监听器

[英]Keyboard shortcuts and action listeners

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! 想知道如何将键盘键链接到netbeans中的JButton,从oracle下载的KeyEventDemo程序可以让您按下一个键并告诉您键码,现在我想知道如何实现它,在计算器项目上工作,我已经具备了能力单击任何按钮并使其为+-/*输入,所以现在我想知道如何将2链接在一起,本质上我试图弄清楚如何检查方法中按下了哪个键,然后根据他们按下的内容运行一个方法! thanks for any info! 感谢您提供任何信息!

See How to Use Key Bindings . 请参阅如何使用键绑定 Basically you bind a KeyStroke to an Action. 基本上,您将KeyStroke绑定到Action。 The tutorial also has a section on How to Use Actions. 本教程还包含有关如何使用动作的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM