title: JavaFX - How to create many windows from your main method?
body: <p>I want to be able create multiple charts each in different windows, but I am struggling to do so in JavaFX. Because the UI is an 'extra' of the application, I wanted to launch the UI separately and separate it from the main program logic, thus I have the following code:</p>
  
  <pre><code>public class UI extends Application {
      private Stage stage;
  
      @Override
      public void start(Stage stage) {
          this.stage = stage; // I don't really plan on even using this, but I've left this here so that I can break on it.
      }
  
      public Stage getStage() {
          return this.stage;
      }
  }
  
  public class Program {
      public static void main(String[] args) {
          // do other stuff
  
          Application.launch(UI.class, args);
          UI ui = new UI();
          // I want to create multiple windows (of charts) here, like this:
          Chart c1 = new Chart("c1");
          Chart c2 = new Chart("c2");
      }
  }
  
  public class Chart {
      public Chart(String title) {
          Stage stage = new Stage();
          // ...
          stage.show();
      }
  }
  </code></pre>
  
  <p>As you can see, this is a mess, just like my understanding of JavaFX. In fact, the code executes infinitely because of a loop in the Application class.</p>
  
  <p>I'm very confused as to how I can create multiple stages. From what I've understood, by calling the <code>Application.launch</code> method, the Application class then calls the <code>start</code> method in the UI class. This does indeed happen, but as mentioned before, it becomes stuck there. However, I don't actually want to create a stage of type UI, I want to create many Chart stages, but it seems that in order for the application to even begin, I must have a <code>start</code> method.</p>
  
  <p>Can anyone help me get my desired outcome of creating multiple windows?</p>