0

I work on a project in Java for school, and I have a problem with JOptionPane.showInputDialog().

My question is: What does JOptionPane.showInputDialog() return if I enter nothing into the field and then hit "OK"?

I tried to find it out by myself with this test-code:

public static void main(String[] args) {
    String test = JOptionPane.showInputDialog("Please enter:");
    if (test==""){
        System.out.println("Found it");
    }else{
        System.out.println(test);
    }
}

This doesn't work, as I said. It will print out the variable test, instead of the string "Found it".

What must I enter in the if-query in case I enter nothing in the field and then hit 'OK'?

Excuse my English, I'm Swiss.

Simon
  • 1
  • 1

1 Answers1

0

try this

    public static void main(String[] args) {
        String test = JOptionPane.showInputDialog("Please enter:");
        if (test==null){
            System.out.println("Found it");
        }else{
            System.out.println(test);
        }
    }
Mostafiz
  • 7,243
  • 3
  • 28
  • 42
Joey
  • 154
  • 5
  • 18