How to get the arrow keys to work in 2D game?

I am designing a 2D game (Applet) in which the objective is to move a dot from one end of the room to the other.how do i get the dot to move in all 4 directions, please help.If you may, please mention a few EXCEPTIONAL tutorials on JAVA game design.
[270 byte] By [Akshay_87a] at [2007-10-1 21:48:47]
# 1

The best (?) way is to use a KeyListener. http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html

In the class that you want the keyevent to occur, put this in your class declaration implements KeyListener {

Then somewhere in that class, put addkeyListener(this);

. You need to have three methods in this class - keyTyped(KeyEvent e), keyPressed(KeyEvent e) and keyReleased(KeyEvent e).

Here's a sample.

public class Example extends JFrame implements KeyListener

{

//some code goes here...

public void keyTyped (KeyEvent event) {}

public void keyReleased (KeyEvent event) {}

public void keyPressed (KeyEvent event)

{

int key = event.getSource();

if (key == KeyEvent.VK_UP)

{

//etc.

}

}

warriornessa at 2007-7-13 7:51:41 > top of Java-index,Other Topics,Java Game Development...
# 2

A tip is to use Boolean variables to keep track if a key is being pressed, something like

public void keyTyped(KeyEvent e) {}

public void keyPressed(KeyEvent e) {

if(e.getKeyCode() == 1) {

someButton = true;

}

}

public void keyReleased(KeyEvent e) {

if(e.getKeyCode() == 1) {

someButton = false;

}

}

T10a at 2007-7-13 7:51:41 > top of Java-index,Other Topics,Java Game Development...
# 3
Oh, yeah, it should be getKeyCode() instead of getSource(). getSource is for actionListener >_>
warriornessa at 2007-7-13 7:51:41 > top of Java-index,Other Topics,Java Game Development...