我想使用实际的Controller创建新的Stage,因为我需要访问我保存数据的Base。在新窗口中,我想将新用户添加到我的Base类中,在返回主窗口后,我希望能够访问我在其中添加新人的类Base。我怎么能这样做?
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);
}
}
编辑: 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);
}
}
}