简体   繁体   中英

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! thanks for any info!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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