【问题标题】:How do i open another GUI from a GUI in javafx如何从 javafx 中的 GUI 打开另一个 GUI
【发布时间】:2021-07-04 21:21:16
【问题描述】:

我正在尝试使用 javaFX 制作一个带有 GUI 的库存系统,我为电视编写了一个 gui,现在另一个让所有者决定在使用后按我想要的添加按钮放入多少调用 TVGUI 让客户指定更多内容,但使用此代码给我一个错误 “JavaFX 应用程序线程”java.lang.IllegalStateException:不能多次调用应用程序启动 还有其他我可以做到的吗?感谢您的帮助

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();
        



        }

    }```

【问题讨论】:

标签: javafx


【解决方案1】:

您可以创建一个新的舞台并显示它。您可以将所有内容添加到此阶段,就像将任何内容添加到主阶段一样。

要显示第二个窗口,您只需要创建一个新的舞台并显示它:

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

我认为您不能同时在两个阶段上运行两个单独的循环,例如,您需要多线程,但我不确定,不要认为我的话是理所当然的。

【讨论】:

    猜你喜欢
    • 2017-03-13
    • 2013-01-18
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2016-05-26
    相关资源
    最近更新 更多