The moose likes Applets and the fly likes arrow keys in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "arrow keys in java?" Watch "arrow keys in java?" New topic

arrow keys in java?

ajay smith

Joined: Feb 02, 2013
Posts: 11
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

Joined: Jan 10, 2002
Posts: 63838

Swing? Console? HTML? Some context is needed.

[Asking smart questions] [About Bear] [Books by Bear]
ajay smith

Joined: Feb 02, 2013
Posts: 11
It's in an applet using AWT, trying to make something move
Darryl Burke

Joined: May 03, 2008
Posts: 5115

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.

luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: arrow keys in java?
jQuery in Action, 3rd edition