keyListener problem

Hello. I have made an keyListener. But it dosent work as I whant to. The problem is that I never make a match into my "if". Any idea why?

// the key listener class where I convert the char to an String

publicvoid keyPressed(KeyEvent e){

perf.key(e.getKeyChar()+"");

view.repaint();

}

// the key method and it never go into my first "if" statement. Why?

publicvoid key(String str){

if(str =="q"){

array[0][0] ="a";

}

// always just gets here and put in a "b"

else array[0][0] ="b";

}

Thanks in advance!

[1145 byte] By [Hunter78a] at [2007-11-27 6:31:31]
# 1
> str == "q"compare objects with equals(), not ==
Hippolytea at 2007-7-12 17:56:24 > top of Java-index,Java Essentials,New To Java...
# 2

Also, I tend to avoid KeyListener (so far, keyboard bindings work better for me: http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html)...

you should be careful about the distinction between key codes and key chars

and between key pressed/released and key typed. Read this page: http://java.sun.com/javase/6/docs/api/java/awt/event/KeyEvent.html

Hippolytea at 2007-7-12 17:56:24 > top of Java-index,Java Essentials,New To Java...
# 3
Here's an explanation. http://www.ibm.com/developerworks/java/library/j-ebb0917a.html
CaptainMorgan08a at 2007-7-12 17:56:24 > top of Java-index,Java Essentials,New To Java...
# 4
NICE. Had totaly forgoten about that. To mutch Haskell for me ^^Thanks a lot!edit: thanks for the tip pages!!Message was edited by: Hunter78
Hunter78a at 2007-7-12 17:56:24 > top of Java-index,Java Essentials,New To Java...