1

I am trying to make a stock system with a GUI using javaFX ive coded a gui for the TV and now another one for letting the owner to decide what how much to put in, after the use pressed the add button I want to call the TVGUI to let the customer specify more thing but using this code gives me an error of "JavaFX Application Thread" java.lang.IllegalStateException: Application launch must not be called more than once Is there anyway else that I can do this? Thanks for the helps

import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class addstock extends Application{
    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage PrimaryStage)throws NumberFormatException {
        BorderPane Bpane = new BorderPane();
        
        FlowPane fpane = new FlowPane();
        fpane.setPadding(new Insets(10));
        Text title = new Text("ADD STOCK");
        title.setFont(Font.font("Courier", FontWeight.EXTRA_BOLD,FontPosture.REGULAR, 22) );
        Text Ttotal = new Text("  How many products to add?  ");
        Ttotal.setFont(new Font("Times New Roman", 16));    
        TextField enter = new TextField();
        enter.setPrefColumnCount(3);
        fpane.getChildren().addAll(title,Ttotal,enter); 
        
        fpane.setAlignment(Pos.CENTER);
        Bpane.setTop(fpane);
        Button btSave = new Button();
        btSave.setText("Add");
        
        btSave.setOnAction(e-> 
        Application.launch(TVGUI.class));
        
        fpane.getChildren().addAll(btSave); 
        
        Scene scene = new Scene(Bpane,460,400);
        PrimaryStage.setTitle("Stock Deduct");
        PrimaryStage.setResizable(false);
        PrimaryStage.setScene(scene);
        PrimaryStage.show();
        



        }

    }```
  • 3
    If it is all one program, why not just have different stages? – SedJ601 Apr 09 '21 at 04:48
  • Does this help? https://stackoverflow.com/questions/10486731/how-to-create-a-modal-window-in-javafx-2-1 – Abra Apr 09 '21 at 07:13
  • 1
    As @Sedrick suggested you can have different/multiple stages in one application. But if you really want it to be 2 applications you can maybe start the other application using the ProcessBuilder. https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html – George R Apr 09 '21 at 09:42

1 Answers1

0

You can create a new Stage and show it. You can add everything to this stage the same way you'd add anything to your main stage.

To display a second window, you only need to create a new Stage and show it :

btSave.setOnAction(e-> {
    Stage stg = new Stage();
    stg.show();
});

I don't think you can run two separate loops on both stages at the same time for example, you would need multi threading for this, but I'm not sure, don't take my words for granted.

Nephty
  • 140
  • 1
  • 7