Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 359
CMOS Avatar asked Jan 19 '23 10:01

CMOS


1 Answers

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.

like image 120
camickr Avatar answered Jan 31 '23 06:01

camickr