0
enter.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e)
        {
            User = input.getText();

            if (User == "hello") {
                Console = "Hi User!";
            }

            output.setText("User: " + User + "\n" + "Console: " + Console);
        }
    });      

When I run it, it displays the text on the GUI. But why is it that the console doesn't respond. I did a system.out.prinln on User when I wrote "hello" Thats exactly hat it said, why is this if statement not working?

1 Answers1

0

You need to compare String using .equals method not ==, so try to change you code to something like:

if (User.equals("hello")) {
    Console = "Hi User!";
}

Read more about How to Compare String in java

Community
  • 1
  • 1
Salah
  • 8,567
  • 3
  • 26
  • 43