Keyboard shortcuts and action listeners

It's amazing how to associate a keyboard key with JButton in netbeans, the downloaded KeyEventDemo program from oracle, which allows you to press a key, and it tells you the key code. Now they are interested in how to implement this while working on the project of the calculator, and I already have the ability to click on any button and have it as + , - , / , * or enter , so now I wonder how to link 2 together, in fact, I I’m trying how to check which key is pressed in the method, and then run the method depending on what they pressed! Thanks for any info!

+4
source share
1 answer

See How to use key bindings . You basically bind KeyStroke to Action. The tutorial also has a section on β€œHow to use actions.”

+8
source

All Articles