keyListener

Trying to make my first keyListener but dosent even run(no compile errors)

Am I missing something as you can see?

//adding the listener to the contructor

KeyListener k =new click();

addKeyListener(k);

//the Listerner

privateclass clickimplements KeyListener{

publicvoid keyPressed(KeyEvent e){

char klick = e.getKeyChar();

//perf.score();

//perf.level();

//perf.time();

perf.key(klick);

System.out.println("this text is not showning when hiting a key");

repaint();

}

publicvoid keyTyped(KeyEvent e){}

publicvoid keyReleased(KeyEvent e){}

}

[1423 byte] By [Hunter78a] at [2007-11-27 6:19:04]
# 1

it means that the perf.key() call has the same effect to a "return", in the keyPressed method

since it returns, the sysout won't appear

why does it return:

key() may contain :

- a return statement

- a System.exit() call

- a try {} catch () {} block, with nothing inside the catch block, so nothing happens in the console

calvino_inda at 2007-7-12 17:33:23 > top of Java-index,Java Essentials,Java Programming...
# 2
What is it you added the listener to, and where do you type?
CeciNEstPasUnProgrammeura at 2007-7-12 17:33:23 > top of Java-index,Java Essentials,Java Programming...
# 3
aha, dont type anywhere. Just added it to an view class(JFrame) ^^. Will try to add it to some kind of box
Hunter78a at 2007-7-12 17:33:23 > top of Java-index,Java Essentials,Java Programming...
# 4
you have to type something in the jframe windows, to activate the listenerthe listener method is "keypressed" ; if no key is pressed while the jframe is on top, nothing will never happen
calvino_inda at 2007-7-12 17:33:23 > top of Java-index,Java Essentials,Java Programming...