swing - keyReleased() method with Key Bindings in Java? -


i'm little bit new key bindings, have been using keylisteners majority until when keylisteners proved biggest obstacle. i'm wondering how program keyreleased-like event keybindings. keylisteners provided easy 3 methods: keypressed, keytyped, , keyreleased, i'm little bit confused how make happen key bindings.

basically, when user presses up, want object move upwards. when user releases up, object should move downwards automatically simulate basic gravity. here's little bit of code showing upaction class.

class upaction extends abstractaction {     public void actionperformed(actionevent tf)     {         north = true;         helitimer.start();         helitimer.start();         helitimer2.start();         repaint();     } } 

the 3 helitimers timer objects start series of timers increment y position of object continuously , smoothly. when action upaction invoked, class upaction called , 3 timers start in order move object.

is there anyway make when user releases up, action no longer invoked , timers stop?

thanks lot!

i'm wondering how program keyreleased-like event keybindings

exactly same way keypressed event. difference in keystroke. read keystroke api, shows how create keystroke keyreleased event. there couple of different ways depending on how want create keystroke.

the keystroke methods assume keypressed, need add additional parameter or additional keyword keyreleased event. don't know method using create keystroke can't tell exact change. check api details.

the 3 helitimers timer objects start series of timers increment y position of object continuously , smoothly

you should not need 3 timer this. 1 timer should work satisfactorily.

is there anyway make when user releases up, action no longer invoked , timers stop?

if can "start" timer in keypress action, can "stop" timer in keyreleasedaction. need reference timer. based on code posted defined timer class variable should not issue.

but when user releases up, object should move downwards automatically simulate basic gravity

sounds me need timer this.

another option have timer running. when key pressed make y increment negative value. when key released make y increment positive value.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -