如何在 JavaFx w/o GUI 生成器、FXML、swing 或 awt 中创建打开另一个 window 的按钮?

How to create button opening another window in JavaFx w/o GUI builder, FXML, swing, or awt?

我需要创建一个按钮来在 java fx 中打开一个 window。不摇摆。没有 fxml。

一个。你能有一个以上的阶段吗?我认为不是,但我看到一个网站另有说法。

乙。我是否必须让按钮创建一个 class 来扩展应用程序,覆盖 start() ...

我查看了以下无济于事。我已经看到了很多,我只是不明白那里有什么或如何实施它。如何修改我的代码以使其工作?

https://o7planning.org/en/11533/opening-a-new-window-in-javafx
https://coderanch.com/t/663804/java/call-window-click-button-current
https://o7planning.org/en/11533/opening-a-new-window-in-javafx

Button to push new customers onto queue. Opens a new popu window (stage) to enter customer information.

        btSave.setText("Add");
        btSave.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {                

                //SCENE 3 OF 3: ADD SCENE, Pane & Nodes
                GridPane addPane = new GridPane();

                //add nodes
                addPane.add(new Label("Customer Name"), 1,1);
                addPane.add(tfName, 1,2);
                addPane.add(new Label("Size of Party"), 1,3);
                addPane.add(tfParty, 1,4);
                addPane.add(new Label("Customer Phone Number"), 1,5);
                addPane.add(tfPhone, 1,6);
                addPane.add(btSave, 1, 7);

                Scene addScene = new Scene(addPane, 300, 250);
                primaryStage.setTitle("Add Customer to Queue");
                primaryStage.setScene(addScene);
                primaryStage.show();

    //                Customer cust = new Customer();
    //                cust.name = tfName.getText();
    //                cust.party = Integer.parseInt(tfParty.getText());
    //                cust.phone = Integer.parseInt(tfPhone.getText()); 
    //                qLine.offer(cust);
                }
            });

I would like the button to show "Add" and would like it to open a new window when clicked.

如果您询问关于打开新舞台的问题,以下代码可能对您有所帮助。

Button btSave = new Button();
btSave.setText("Add");
btSave.setOnAction(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {                

        //SCENE 3 OF 3: ADD SCENE, Pane & Nodes
        GridPane addPane = new GridPane();

        //add nodes
        addPane.add(new Label("Customer Name"), 1,1);
        addPane.add(tfName, 1,2);
        addPane.add(new Label("Size of Party"), 1,3);
        addPane.add(tfParty, 1,4);
        addPane.add(new Label("Customer Phone Number"), 1,5);
        addPane.add(tfPhone, 1,6);
        addPane.add(btSave, 1, 7);

        Stage addStage = new Stage();
        Scene addScene = new Scene(addPane, 300, 250);
        addStage.setTitle("Add Customer to Queue");
        addStage.setScene(addScene);
        addStage.show();
    }
});