0
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?

richarbernal
  • 1,063
  • 2
  • 14
  • 32
BaconMan97
  • 67
  • 1
  • 9

1 Answers1

2

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")){
Smi
  • 13,850
  • 9
  • 56
  • 64