如何在保留数据的同时返回上一场景?

时间:2019-04-14 20:56:18

标签: javafx

我试图通过从用户输入帐户的输入来模拟银行系统,然后返回主菜单。但是,当我加载菜单场景返回主菜单时,数据就消失了。

我试图将数据添加到ArrayList中,但是在加载主菜单后数据也消失了。

我的主班

public class BankSystemMain extends Application {
    public static Scene scene;
    public static Parent root;

    @Override
    public void start(Stage primaryStage) throws IOException{
        root = FXMLLoader.load(BankSystemMain.class.getResource("Options.fxml"));
        scene = new Scene(root);
        FXMLLoader loader = (FXMLLoader) scene.getUserData();
        scene.setUserData(loader);
        primaryStage.setTitle("Banking System");
        primaryStage.setScene(scene);
        primaryStage.show();
    }




    public static void main(String[] args) {
        launch(args);

    }

}

我的控制器类

public class BankSystemController implements Initializable {

    ArrayList<String> data = new ArrayList<String>();


    @FXML
    private TextField accNum;

    @FXML
    private TextField firstName;

    @FXML
    private TextField lastName;

    @FXML
    private TextField phoneNum;

    @FXML
    private TextField email;

    @FXML
    private TextField balance;

    @FXML
    private TextField fee;




    @FXML
    private void ProceedButtonPressed(ActionEvent event) throws IOException {
        data.add(accNum.getText());
        data.add(firstName.getText());
        data.add(lastName.getText());
        data.add(phoneNum.getText());
        data.add(email.getText());
        data.add(balance.getText());
        data.add(fee.getText());

        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        stage.setScene(BankSystemMain.scene);
        stage.show();
    }

我希望我的数据位于ArrayList中。

0 个答案:

没有答案