0

I'm making a video game that's having trouble registering key releases with a Key Listener. Everyone here at Stack Overflow suggested I should try Key Bindings instead. I started reading up on Key Bindings and didn't understand the use of an Action in using Key Binding. Could someone please give me an example of the writing and use of an Action class in using a Key Binding in a way when an end user presses a key while focused on a JPanel some code gets executed? And how an Action plays a role in that?

Ps. I read through http://docs.oracle.com/javase/tutorial/uiswing/misc/action.html and http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html If you have any other links with explanations and examples that'd be awesome too =)

ilgaar
  • 804
  • 1
  • 12
  • 31
Algebra is Awesome
  • 273
  • 1
  • 2
  • 9
  • 3
    Something like [this](http://stackoverflow.com/questions/11401053/pong-paddle-bottom-doesnt-move-up-when-up-key-is-pressed/11407148#11407148) or [this](http://stackoverflow.com/questions/16926614/how-to-implement-an-actionlistener-for-space-bar-as-action-event/16927647#16927647) or [this](http://stackoverflow.com/questions/11917377/do-something-once-the-key-is-held-and-repeat-when-its-released-and-repressed/11917604#11917604) or [this](http://stackoverflow.com/questions/23100725/using-keylistener-with-java/23100795#23100795) – MadProgrammer Feb 24 '15 at 21:28
  • Too bad he can't upvote the 4 posts with his rep :( – Jean-François Savard Feb 24 '15 at 22:49
  • I tried doing similar initialization as in all four examples and it keeps throwing errors in Eclipse. I have nooo idea why it's not working exactly but I looked at the Oracle site about InputMap and there isn't a "getInputMap" method for starters. Am I missing something here? – Algebra is Awesome Feb 25 '15 at 02:09
  • Take a look at this question: http://stackoverflow.com/a/23100795/108350. My one comment is that I tried: WHEN_IN_FOCUSED_WINDOW, and that calls your handler any time you click in on the (whole) window. If you just want a field stick with the default. – will Mar 15 '17 at 22:24

0 Answers0