Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  KeyBindings vs KeyListeners  (Read 534 times)
0 Members and 1 Guest are viewing this topic.
Offline Troncoso

Junior Member


Medals: 1



« Posted 2012-11-18 01:44:12 »

I'm so confused about Keyboard input in Java games. Everytime I look up something like "Keyboard input for Java games", I get these examples and tutorials that use KeyListeners. Then, everytime I look up issues I'm having, people say that you should use Key Bindings. But, there are no Key Binding tutorials besides Oracle's over complicated one.

If it's constantly suggested to use key bindings over keyListeners, then why are all examples/tutorials using keylisteners?
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #1 - Posted 2012-11-18 02:12:48 »

Hi

You need an API based on events (with listeners, like in NEWT, AWT, Swing, SWT, QtJambi, ...) or a polling API (like JInput) to implement key bindings anyway.

Offline Troncoso

Junior Member


Medals: 1



« Reply #2 - Posted 2012-11-18 02:23:42 »

Well, yes. But, you can still use KeyListeners without KeyBindings.
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #3 - Posted 2012-11-18 05:09:56 »

Who the hell told you to use key bindings? XD

You do want to use KeyListeners.

Offline Troncoso

Junior Member


Medals: 1



« Reply #4 - Posted 2012-11-18 06:37:12 »

Well, I was having focusing issues when using KeyListeners. Everything I searched for game me people saying that the proper way was to use KeyBindings, then they would link the oracle tutorial.
Offline Cero
« Reply #5 - Posted 2012-11-18 15:26:22 »

you should post some code. I'm sure this is actually a problem of terminology. A keylistener is a part of code, in swing a thread, which waits for hardware keyboard inputs and forwards them to your code. Keybindings are simple "what key does which action".  "Key SPACE jumps"  Pointing that is a "binding"

Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #6 - Posted 2012-11-18 16:16:02 »

Well, yes. But, you can still use KeyListeners without KeyBindings.
No you can't, you have to tell what to do when a key is pressed, released, typed, you have to run an action depending on a key, that's a key binding.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (49 views)
2013-05-18 05:29:12

alaslipknot (58 views)
2013-05-17 05:24:48

gouessej (88 views)
2013-05-16 08:53:38

gouessej (86 views)
2013-05-16 08:17:58

theagentd (95 views)
2013-05-15 23:01:13

theagentd (88 views)
2013-05-15 23:00:54

StreetDoggy (133 views)
2013-05-14 23:56:26

kutucuk (154 views)
2013-05-13 01:10:36

kutucuk (154 views)
2013-05-12 23:36:09

UnluckyDevil (164 views)
2013-05-12 13:09:57
Complex number cookbook
by Roquen
2013-04-24 20:47:31

2D Dynamic Lighting
by Oskuro
2013-04-18 00:46:12

2D Dynamic Lighting
by Oskuro
2013-04-18 00:45:57

2D Dynamic Lighting
by Oskuro
2013-04-18 00:23:20

Noise (bandpassed white)
by Roquen
2013-04-06 01:36:01

Noise (bandpassed white)
by Roquen
2013-04-04 00:17:38

Java Data structures
by Roquen
2013-03-29 21:21:12

Topic Request
by kutucuk
2013-03-23 05:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.226 seconds with 21 queries.