title: How do I use JOptionPane in an If statement?
body: <p>I am new to learning Java. In an assignment, I am using If/Else statements and trying to display information in JOptionPane. Here is a quick example I made to show the issue I'm having. I want to display "Hello there" if the input in the string hello is equal to "hey".</p>
  
  <p>Nothing comes up.</p>
  
  <p>I noticed that if I put the JOptionPane statement earlier in the code, such as next to the scanner declaration, it will work. Also, if I do that AND leave the other JOptionPane in the original location, there will be TWO dialog boxes.</p>
  
  <p>I was thinking that maybe the scanner input is messing with it somehow. </p>
  
  <pre><code>import javax.swing.JOptionPane; 
  import java.util.Scanner;
  
  public class HW2 {
      public static void main( String args[] ) {
          Scanner kb = new Scanner(System.in);
          System.out.print("Say hey");
          String hello = kb.nextLine();
          if (hello.equals("hey")) 
              JOptionPane.showMessageDialog(null, "Hello there!");
          kb.close();
      }
  }
  </code></pre>
  
  <p>Does anyone know why the dialog box isn't showing up? Thanks!</p>