In my program I want to update my model from sliders, and it does so like this
public class Controller implements Initializable {
@FXML
private Model model = new Model();
@FXML
public void editDone() throws Exception {
model.setStarterCash((int)cashSlider.getValue());
model.setNumAction((int)acSlider.getValue());
model.setNumSalary((int)scSlider.getValue());
model.setNumCareer((int)ccSlider.getValue());
Stage doneStage = (Stage)editSave.getScene().getWindow();
Parent doneView = FXMLLoader.load(getClass().getResource("View/editMenu.fxml"));
Scene doneScene = new Scene(doneView);
doneStage.setScene(doneScene);
doneStage.show();
System.out.println("Starter cash set to: " + model.getStarterCash());
System.out.println("Action Deck amount set to: " + model.getNumAction());
System.out.println("Salary Deck amount set to: " + model.getNumSalary());
System.out.println("Career Deck amount set to: " + model.getNumCareer());
}
}
Which prints it out into the console
Starter cash set to: 350000
Action Deck amount set to: 75
Salary Deck amount set to: 20
Career Deck amount set to: 11
But when the scene changes and I try to check my if my values are still the same in another scene (with getters), it get reset/displays 0. Am I properly updating my model correctly?
UPDATE This is the model class. The model contains setters and getters for data from the an "options" scene but when I try access the values I've set from said scene in a different scene, say "start game" scene, it outputs 0.
package Model;
public class Model {
private Board b;
private int starterCash;
private int numAction;
private int numSalary;
private int numCareer;
private int numPlayers;
public Model () {
b = new Board();
}
public int getStarterCash() {
return starterCash;
}
public int getNumAction() {
return numAction;
}
public int getNumCareer() {
return numCareer;
}
public int getNumSalary() {
return numSalary;
}
public int getNumPlayers() {
return numPlayers;
}
public void setNumPlayers(int numPlayers) {
this.numPlayers = numPlayers;
}
public void setStarterCash(int starterCash) {
this.starterCash = starterCash;
}
public void setNumAction(int numAction) {
this.numAction = numAction;
}
public void setNumCareer(int numCareer) {
this.numCareer = numCareer;
}
public void setNumSalary(int numSalary) {
this.numSalary = numSalary;
}
public Board getB() {
return b;
}
Here's the Main class where the application starts, if it is needed.
package View;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("mainMenu.fxml"));
primaryStage.setTitle("That's Life!");
primaryStage.setScene(new Scene(root, 1024, 576));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}