0

I am writing a simple program to launch a scene 3 times, but it says that in JavaFX.application... launch(args) can only be used once. Is there anything I could use to do this? I did some research and found Platform.runLater(), but I don't know how I would incorporate that.

public void start(Stage primaryStage) { 
    Pane pane = new Pane();

Circle c = new Circle();
    c.setCenterX(200);
    c.setCenterY(50);
    c.setRadius(25);
    c.setStrokeWidth(4);
    c.setStroke(Color.ORANGE);
    c.setFill(Color.WHITE);

pane.getChildren().add(c);
Scene scene = new Scene(pane, 300, 300);
        primaryStage.setTitle("Circle");
        primaryStage.setScene(scene); 
        primaryStage.show();
}

public static void main(String []args){
     for(int i=0;i<3;i++){
         launch(args);}
}
  • 2
    Move the loop to the `start()` method, creating a new stage on each iteration. `Platform.runLater()` is used to execute code on the FX Application Thread, which has absolutely nothing to do with what you are asking. – James_D Sep 22 '17 at 14:18
  • Note that `Platform.runLater` is unnecessary, if you are on the application thread, like in the `start` method. The other parts of the answer in the dupe should be applicable. Note that this does not execute the proper launch process. You'd need to call `init` yourself for this and call `stop` for all application instances when the "main" application stops... – fabian Sep 22 '17 at 14:37
  • @James_D I am new to JavaFX and I've never created a new stage. Would I put **Stage myStage = new Stage** within the for loop? – Dawson Naccarato Sep 22 '17 at 14:41
  • Indeed, calling "lifecycle" methods, such as `init()`, `start()`, and `stop()`, yourself is generally not recommended. If all you want to do is show three windows when the application starts, show three windows from the `start()` method. – James_D Sep 22 '17 at 14:45
  • 1
    @DawsonNaccarato Yes, you create new stages in exactly the same way you create other objects in Java. – James_D Sep 22 '17 at 14:45

0 Answers0