Question

public static void displayInfo(KeyEvent e){
int id = e.getID();

String keyString;
   char c = e.getKeyChar();
    keyString =  ""+c;


    if (keyString=="w"){
        System.out.print("FACE");
    }
}

this is my code and for whatever reason it wont work. Help please?

Was it helpful?

Solution

You should not compare strings with the == operator. Instead, use the equals method. So, change this line:

if (keyString=="w"){

to this:

if (keyString.equals("w")){
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top