title: How to close a stage after a certain amount of time JavaFX
body: <p>I'm currently working with two controller classes.</p>
  
  <p>In Controller1 it creates a new stage that opens on top of the main one. </p>
  
  <pre><code>Stage stage = new Stage();
  Parent root = FXMLLoader.load(getClass().getResource("Controller2.fxml"));
  Scene scene = new Scene(root);
  stage.setScene(scene);
  stage.show();
  </code></pre>
  
  <p>Now once that stage is open, I want it to stay open for about 5 seconds before closing itself.</p>
  
  <p>Within Controller2, I've tried implementing something like</p>
  
  <pre><code>long mTime = System.currentTimeMillis();
  long end = mTime + 5000; // 5 seconds 
  
  while (System.currentTimeMillis() &gt; end) 
  {
        //close this stage  
  } 
  </code></pre>
  
  <p>but I have no idea what to put inside the while loop to close it. I've tried all sorts and nothing works.</p>