title: How to wait for user input when using JTextFields
body: <p>I recently built and completed the first stage of a program in java that worked with IDE using System.out.println(); and what not. Now, I want to give this program a GUI and I ran into an issue. Here is my MCV example (or at least I think it is, let me know if it is not).</p>
  
  <pre><code>import java.net.*;
  import java.net.UnknownHostException;
  import java.net.NoRouteToHostException;
  import java.io.*;
  import net.sf.json.*;
  import org.apache.commons.lang.exception.*;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JTextField;
  import javax.swing.JPanel;
  import javax.swing.SwingConstants;
  import javax.swing.BoxLayout;
  import javax.swing.JOptionPane;
  import java.awt.Component;
  import java.awt.Container;
  import java.util.Scanner;
  
  
  public class WOT_PlayerComp_V2
  {
  
     public static JFrame f;
     public static JLabel resultLabel;
     public static JPanel p;
     public static JTextField t;
     public static String comparisonResults = "";
     public static String holder = "";
     public static String playerName = "";
     public boolean gameIsStillRunning = true;
  
     public static void testGUI()
     {
        f = new JFrame();
  
        addComponentsToPane(f.getContentPane());
  
  
  
        f.setSize(300, 400);
        f.setLocation(200, 200);
        // f.setResizable(false);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
  
     }
  
     public static void addComponentsToPane(Container c)
     {
        c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
  
        p = new JPanel();
        t = new JTextField(15);
        //t.setDocument(new JTextField_wLimit(50));
        //You can ignore this line, it is what I used to limit the input of my textfield
        resultLabel = new JLabel();
  
  
        //html makes the br have purpose, p makes it wrap
        resultLabel.setHorizontalAlignment(SwingConstants.CENTER);
        resultLabel.setVerticalAlignment(SwingConstants.TOP);
        resultLabel.setSize(50, 50);
  
        c.add(t);
        c.add(resultLabel);
  
  
     }
  
     public WOT_PlayerComp_V2()
     {
  
        testGUI();
  
     //... Lots of irrelevant code
  
        resultLabel.setText("Enter your username.");
  
        while(gameIsStillRunning)
        {
  
        //irrelevant code
  
           playerName = t.getText();//scans user input
           t.setText("");
  
        //more irrelevant code
        }
  
        //if(playerName == null || playerName.equals(""))
        //^^ it shouldn't go into here, I want my while loop to wait 
        //for user input like it did when i was using a Scanner object
        //
  
     }
  
     public static void main(String[] args)
     {
  
        WOT_PlayerComp_V2 w = new WOT_PlayerComp_V2();
  
     }
  
  }
  </code></pre>
  
  <p>Basically, prior to me using a JTextField object, I was using a Scanner object. The Scanner object would actually stop my while loop and run that method, then continue. I want to know if this is possible with a JTextField. I want to be able to stop the for loop in the middle and wait for the user input. It doesn't seem as big a problem with the MCV example I have above, but the code I am using is based heavily on input and will respond to a user entering null or empty strings. As a result, it will do what it was meant to do, respond to correct user input, and this will only last for one iteration, then it will keep taking input from the JTextField, since it is in a while loop. That's my problem.</p>