Doesn't recognize string value?
Alright, so I was trying to code a simple command system but I ran into a problem along the way. I tried to do the code below. But even when commandBar was equal to exit it would print: Command Value: "exit". So I am not sure what I am doing wrong. Any help is appreciated. Thanks!
Code:
public void actionPerformed(ActionEvent e) {
System.out.println("actionPerformed: " + e.getSource().toString());
if(e.getSource() == commandEnter){
String command = commandBar.getText();
if(command == "exit"){
dispose();
System.exit(0);
}else{
System.out.println("Command not recognized");
System.out.println("Command Value: \""+command+"\"\n");
}
}else if(e.getSource() == exit){
dispose();
System.exit(0);
}
}
Re: Doesn't recognize string value?
Nevermind. I fixed it by doing the following for line 5:
Code:
if(command.equals("exit")){
Thanks anyways.