key listeners

I'm adding a KeyListener to a JLabel, which when the arrow keys are pressed will change the text of the JLabel. I was wondering if it is possible, in the keyPressed function, to only do this when the arrow keys are pressed, and not any other keys? I' m pretty aure it can be done using ASCII but don't know how to go about it.

Any help would be great!

Thanks,

D.

[392 byte] By [dave_dina] at [2007-9-29 22:26:41]
# 1

public void keyPressed(KeyEvent ke){

switch(ke.getKeyCode()){

case(KeyEvent.VK_LEFT ):

changeText();

break;

case(KeyEvent.VK_RIGHT):

changeText();

break;

case(KeyEvent.VK_UP):

changeText();

break;

case(KeyEvent.VK_DOWN):

changeText();

break;

}

}

eeenricoa at 2007-7-16 2:47:58 > top of Java-index,Other Topics,Java Game Development...