So I have an integer number called "size" saved to a controller class called SettingsStageController.java and I want that variable to be accessed through my other controller class file called GameStageController.java but I can't seem to find out how.
SettingsStageController.java
/* has the int size variable stored in this file */
int size = 5;
public void startGame(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("gameStage.fxml"));
root = loader.load();
stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); // ti ston poutso
scene = new Scene(root);
stage.setTitle("DnB: " + Integer.toString(size) + "x" + Integer.toString(size) + " Game");
stage.setScene(scene);
stage.show();
GameStageController gameStageController = loader.getController();
gameStageController.showPane();
}
GameStageController.java
public class GameStageController implements Initializable {
@FXML
Text testText;
@FXML
AnchorPane twoXtwoPane;
@FXML
AnchorPane threeXthreePane;
@FXML
AnchorPane fourXfourPane;
@FXML
AnchorPane fiveXfivePane;
public void showPane() {
switch (/* I WANT TO PUT THE "SIZE" NUMBER HERE" */) {
case 2:
twoXtwoPane.setDisable(false);
twoXtwoPane.setVisible(true);
break;
case 3:
threeXthreePane.setDisable(false);
threeXthreePane.setVisible(true);
break;
case 4:
fourXfourPane.setDisable(false);
fourXfourPane.setVisible(true);
break;
case 5:
fiveXfivePane.setDisable(false);
fiveXfivePane.setVisible(true);
break;
default:
twoXtwoPane.setDisable(false);
twoXtwoPane.setVisible(true);
break;
}
}
}
showPane()being called from? Can’t you just makesizea parameter to that method, or just pass the size to the controller when the relevant FXML is loaded? Create and post a minimal reproducible example.showPane()method is being called from my SettingsStageController.java class file but its location is at the GameStageController.java file I edited some of the code if that helps.public void showPane(int size) { … }and callshowPane(size). It’s not clear what the problem is.