title: JavaFX 8 initialize method
body: <p>So I am trying to do a chat type program using JavaFX for the GUI. I have it so a class that acts as a server will loop and keep adding client connections to it. </p>
  
  <pre><code>public void serverconnection()
  {
      // portnumber was saved from constructor
      try (ServerSocket socket = new ServerSocket(this.portnumber))
      {
          // loop is a bool set to true
          while (loop) 
          {
              // this class extends Thread and has its own overwritten start method
              new myclass(socket.accept()).start();
          }
      }
      catch (IOException e) 
      {
          System.exit(404);
      }
   }
  </code></pre>
  
  <p>so the problem is (I am assuming) was, this loop keeps looping until the program closes. but since I was calling this within the JavaFX's initialize method</p>
  
  <pre><code>public void initialize(URL url, ResourceBundle rb) 
  {
      // constructor, nothing here is needed for this post
      myclass z = new myclass(45234);
      // problem here, since this has a  loop, but
      z.serverconnection();
      // gui wont load till after this is done
      // but serverconnection is only done after program ends
  }    
  </code></pre>
  
  <p>the problem with this is, apparently, the GUI will not load until AFTER initialize has finished, but it will not finish until program closes. After google searching, I could not find any fix for this. I need a way to call a method that will do all this, AFTER initialize method has finished. My client side class is similar to this, but the methods to connect on that are activated on events when clicking a login button. For this serverside one, I am trying to start without any interaction with the user. so is there a way to call a method or make this work AFTER initialize method has ran?</p>