I have an If statement in Java but it doesn't funtion correctly. I put a condition but the if doesn't respect that.
My code :
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name="";
String surname="";
name = txtName.getText().toString();
surname = txtSurname.getText().toString();
if (name!="" && surname!="") {
msgAlarm.setText("<html>Insert all data<br/>before continuing!<html>");
Runnable runnable =
(Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
runnable.run();
}else {
System.out.println("Else Started");
}
However when I run the program and the txtName and txtSurname are empty, Java run first statement.
How can I resolve?
Many Thanks.