Javafx перенос информации со сцены на сцену

Здравствуйте начал изучать фраимворк Javafx и решил для практики написать симулятор войны кубов и по за думке в отдельной сцене пользователь дает настройки кубам а в другой уже с вписанными настройками идет война кубов но я просто не знаю как перенести информацию из одной сцены в другую Вот три контролера

package com.example.gamefx3;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class PlayGameController{
private static PlaySettingsController playSettingsController=new PlaySettingsController();
    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button Ex;
    int number_cubes= playSettingsController.getNumber_cubes();

    @FXML
    private AnchorPane rootPane;

    @FXML
    void Ex_click(ActionEvent event) throws IOException {

        Parent root = FXMLLoader.load(getClass().getResource("PlayMenu.fxml"));
        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }


    @FXML
    void initialize() throws IOException {
        assert Ex != null : "fx:id=\"Ex\" was not injected: check your FXML file 'PlayGame.fxml'.";
        List<Rectangle> list = new ArrayList<>();
        for (int i = 0; i < number_cubes; i++) {
            list.add(new Rectangle(10, 10));
            list.get(i).setFill(Color.RED);
            list.get(i).setLayoutX(10 + i * 20);
            list.get(i).setLayoutY(10);
            rootPane.getChildren().add(list.get(i));
        }
    }
}


package com.example.gamefx3;


import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class PlayMenuController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button Run;

    @FXML
    private Button Settings;

    @FXML
    void Run_click(ActionEvent event) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("PlayGame.fxml"));
        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    @FXML
    void Settings_click(ActionEvent event) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("PlaySettings.fxml"));
        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    @FXML
    void initialize() {
        assert Run != null : "fx:id=\"Run\" was not injected: check your FXML file 'PlayMenu.fxml'.";
        assert Settings != null : "fx:id=\"Settings\" was not injected: check your FXML file 'PlayMenu.fxml'.";

    }

}

package com.example.gamefx3;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;

public  class  PlaySettingsController {

    @FXML
    private ResourceBundle resources;
    @FXML
    private Label myLabel;
    @FXML
    private TextField myTextField;

    public int getNumber_cubes() {
        return number_cubes;
    }

    @FXML
    private Button myButton;
    @FXML
    private URL location;

    @FXML
    private Button Ex;
    int number_cubes = 10;
    @FXML
    void Ex_click(ActionEvent event) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("PlayMenu.fxml"));
        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }


    @FXML
    void exit(KeyEvent event) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("PlaySettings.fxml"));
        Parent root1 = FXMLLoader.load(getClass().getResource("PlayMenu.fxml"));
        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        Scene scene = new Scene(root);
        Scene scene1 = new Scene(root1);
        scene.setOnKeyTyped(e -> {
            if (e.getCode() == KeyCode.K) {
                stage.setScene(scene1);
                stage.show();
            }
        });

    }

    public void myButton_cl(ActionEvent event) {

        try {
            number_cubes = Integer.parseInt(myTextField.getText());

            if (number_cubes <= 50 && number_cubes >= 1) {
                myLabel.setText("Готово");
            } else {
                myLabel.setText("Количество кубов должно быть больше 0 и меньше 51");
            }
        } catch (NumberFormatException e) {
            myLabel.setText("Пишите только цифры пожалуйста");
        } catch (Exception e) {
            myLabel.setText("Ошибка");
        }
    }

    @FXML
    void initialize() {
        assert Ex != null : "fx:id=\"Ex\" was not injected: check your FXML file 'PlaySettings.fxml'.";

    }

}

Тут главный Метод

package com.example.gamefx3;

import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class Main extends Application {

    @Override
    public void start(Stage stage) {
        try {

            Parent root = FXMLLoader.load(getClass().getResource("PlayMenu.fxml"));
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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

Пробовал я гуглить но там требуется создавать отдельный объект в главном классе что в мой код не входит пробовал искать в документации но там чет ногу сломит


Ответы (0 шт):