W
W
WannaCreative2016-08-22 23:06:18
Java
WannaCreative, 2016-08-22 23:06:18

Why does it give the same inscription when pressed?

Good evening!
There is a simple application
HWFy0nQ7jzI.jpg
And also there is a code for it

public class Controller implements Initializable
{
    public static String login = "myCat";

    @FXML
    private Button btn;

    @FXML
    private TextField loginfield;


    public void initialize(URL fxmlFileLocation, ResourceBundle resources)
    {
        btn.setOnAction(
                event ->
                {
                    if (loginfield.getText() == login)
                    {
                        System.out.println("That's right");
                    }

                    if (loginfield.getText() != login && loginfield.getText() != null)
                    {
                        System.out.println("That's not right");
                    }
                }
        );
    }
}

Typing "myCat" in the Login field should show That's right, but it still says That's not right, even if I enter the correct name in the field

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Damir Makhmutov, 2016-08-22
@WannaCreative

And if so?

if (loginfield.getText().equals(login)) {
    System.out.println("That's right");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question