0

I would like create new Stage using actual Controller, because I need to have access to Base where I keep the data. In the new window I want to add new users to my Base class, and after returning to the main window I want to have access to the class Base in which I added new people. How I can do this?

public class Controller  {

private Base base;

@FXML private TextField email;

public void addPersonButtonClicked(ActionEvent event) throws IOException {

    Parent mainView = FXMLLoader.load(getClass().getResource("addPerson.fxml"));
    Scene mainViewScene = new Scene(mainView);

    Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();

    window.setScene(mainViewScene);

    window.show();
}

public void addPersonContinueClicked(){
    Person person = new Person();
    person.setEmail(email.getText());
    base.addPerson(person);
}
} 

Edit: Base.class

public class Base {

private List<Person> personList = new ArrayList();

public Base() {
}

public void addPerson(Person person) {
    if (this.personList.contains(person)) {
        throw new RuntimeException();
    } else {
        this.personList.add(person);
    }
}
}
woljako
  • 39
  • 1
  • 5
  • What is `Base`? Is it your model class? – James_D Jan 31 '18 at 23:00
  • I just added my class to the question – woljako Jan 31 '18 at 23:10
  • 1
    So you are saying you have an existing instance of `Base`, and want to pass it to the controller? Just pass it in the same way you [pass other parameters to a controller](https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml)/ – James_D Jan 31 '18 at 23:14

0 Answers0