-3
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;


public class Example {

    public static void main(String[] args) {

        String name;

        name = JOptionPane.showInputDialog(null, "ENTER TEST BELOW:"," ",3 );

        if (name == "TEST") {

            JOptionPane.showMessageDialog(null, "Welcome " + name + ", It works "," ",  1, new ImageIcon("Pictures/Example.jpg"));

        }

        else {

            JOptionPane.showMessageDialog(null,"Welcome " + name + ", It doesn't work."," ",  1, new ImageIcon("Pictures/Example.jpg"));

        }
    }

}
tbodt
  • 16,609
  • 6
  • 58
  • 83
Quantum
  • 1
  • 1

1 Answers1

2

Instead of comparing the strings with this:

name == "TEST"

you should use this:

name.equals("TEST")

A famous question explains the reason why you need to do this. Essentially, == compares whether name and "TEST" are the same object. They are not the same object, but they have the same contents, and equals tests for the same contents.

Community
  • 1
  • 1
tbodt
  • 16,609
  • 6
  • 58
  • 83