title: How to use a thread to run another JFrame while the main is still running
body: <p>I have a jframe i want to display while my main frame is running. i want to pause my main code, until the user does the necessary actions on the other frame. I've read a lot of solutions but i need to see it done for my code to understand and grasp it fully. i do not want to use jdialog like I've seen listed as an answer before. My main goal is to understand better threading so that i can use what i learn in different cases. </p>
  
  <p>With the code I've created, when running the thread, only just the frame loads, none of the other features are there on the frame. (the frame is simple it has a label, a list the user selects from, and a button to basically return the chosen list value.) its like the thread is cut off from completing or something. </p>
  
  <p>here is my class calling the screen:</p>
  
  <pre><code>public class myThread implements Runnable {
  
      String result = null;
  
      public void run() {
          MessageScreen ms = new MessageScreen();
          ms.setVisible(true);
      }
  
      public String getResult() {
          return result;
      }
  
      public void setResult(String AS) {
          result = AS;
      }
  
  }
  </code></pre>
  
  <p>in my main code, a method is called that is returning a String[] value, with this method at some point i have the following code calling the new thread to get the value necessary to return in the original main method:</p>
  
  <pre><code>    myThread mt = new myThread();
      Thread t = new Thread(mt);
      t.start();
      try {
          t.join();
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
      myreturn = new String[] {"true", mt.getResult()}; 
  </code></pre>
  
  <p>without listing the whole code for the second frame, when the user presses the button, and at the end of the listener tied to the button press the i want to close the frame and return a string that was selected from the list:</p>
  
  <pre><code>jf.dispose();
  myt.setResult(AdminSelection);
  </code></pre>
  
  <p>in the frame class, i have the following instance variables declared:</p>
  
  <pre><code>String AdminSelection = null;
  myThread myt; 
  </code></pre>
  
  <p>i hope this is enough information for someone to help me out and understand whats gone wrong here.</p>