1
if(Game.gameRoom == Room.RoomThree){
                if(key != KeyEvent.VK_SPACE){
                    keycode = e.getKeyCode();
                    Code += KeyEvent.getKeyText(keycode);
                    Code = Code.toLowerCase();
                    System.out.println(Code);
                    if(Code == "switch horses"){
                        handler.addObject(new KeysBtn(300, 385, ID.Key));
                        System.out.println("Correct");
                        Code = "";
                    }
                }

For this code it types out what I type on the key bord the only problem even though i have typed the Code "switch horses" it dose not print Correct in the consol.

Cory
  • 13
  • 6
  • use `Code.equals("switch horses")` –  Apr 24 '18 at 13:32
  • Thank you for your help it works now. Sorry for being stupid. – Cory Apr 24 '18 at 13:33
  • The reason that you should not compare Strings using `==` or `!=` and use the `equals(...)` or the `equalsIgnoreCase(...)` method instead is because `==` checks if the two *object references* are the same which is not what you're interested in. The methods on the other hand check if the two Strings have the same characters in the same order, and that's what matters here. – Hovercraft Full Of Eels Apr 24 '18 at 13:38
  • As an aside, you will want to learn and use [Java naming conventions](http://en.wikipedia.org/wiki/Naming_convention_(programming)#Java). Variable names should all begin with a lower letter while class names with an upper case letter. Learning this and following this will allow us to better understand your code, and would allow you to better understand the code of others. – Hovercraft Full Of Eels Apr 24 '18 at 13:38

0 Answers0