Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

arrow keys in java?

 
ajay smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm trying to build a small game and I have all the logic down, but how does the program know if a key is pressed down? For example:

if( left arrow key is pressed down)
{ move thing left }
else if(right arrow key is pressed down)
{ move thing right }

and so on. I already know how to move the thing, but how do you make java respond to keys being pressed down?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing? Console? HTML? Some context is needed.
 
ajay smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's in an applet using AWT, trying to make something move
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ajay smith wrote:It's in an applet using AWT

AWT has been superseded by Swing more than a decade ago. I stronly recommend that you convert this Applet to a JApplet, and replace the AWT components with their Swing equivalents. You can then use Key Bindings for your purpose.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic