I have a Java FX project and I just got all of the different scenes connected with button actions, but the last thing I have left is not quite working. Once logged into the main scree, I have a homescreen with a table. If you select "Add patient" A new pop up scene opens with a form. I have the button on the form pop up redirecting back to the table homescreen, but the info doesn't save as it's supposed to. Any help is much appreciated. Here's some of the code:
public class homescreenController implements Initializable {
@FXML
private TableView <Table> patientTable;
@FXML
private TableColumn<Table, Integer> PatientNo;
@FXML
private TableColumn<Table, String> LastName;
@FXML
private TableColumn<Table, String> FirstName;
@FXML
private TableColumn<Table, String> DateOfBirth;
@FXML
private Button openPop;
@FXML
private Button Btn2;
@FXML
int iNumber = 1001;
@FXML
final ObservableList <Table> data = FXCollections.observableArrayList(
new Table(iNumber++, "Smith", "Patient1", "1/22/1978"),
new Table(iNumber++, "Roberts", "Patient2", "1/22/1978"),
new Table(iNumber++, "Doe", "Patient3", "1/22/1978")
);
@Override
public void initialize(URL url, ResourceBundle rb) {
PatientNo.setCellValueFactory(new PropertyValueFactory<Table, Integer> ("rPatientNo"));
LastName.setCellValueFactory(new PropertyValueFactory<Table, String>("rLastName"));
FirstName.setCellValueFactory(new PropertyValueFactory<Table, String>("rFirstName"));
DateOfBirth.setCellValueFactory(new PropertyValueFactory<Table, String>("rDateOfBirth"));
patientTable.setItems(data);
}
@FXML
public void handleButtonAction2(ActionEvent event) throws IOException, SQLException {
Parent root = FXMLLoader.load(getClass().getResource("popUp.fxml"));
Scene home_page_scene = new Scene(root);
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.setScene(home_page_scene);
app_stage.show();
}
}
//And the controller for the pop up
public class popUpController extends homescreenController implements Initializable {
@FXML
TextField LastNameField;
@FXML
TextField FirstNameField;
@FXML
TextField DateOfBirthField ;
@Override
public void initialize(URL location, ResourceBundle resources) {
}
@FXML
private void handleButtonAction3 (ActionEvent event) throws IOException, SQLException {
Table entry = new Table(iNumber, LastNameField.getText(), FirstNameField.getText(), DateOfBirthField.getText());
iNumber++;
data.add(entry);
clearForm();
Parent home_page_parent = FXMLLoader.load(getClass().getResource("homescreen.fxml"));
Scene home_page_scene = new Scene(home_page_parent);
Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
app_stage.setScene(home_page_scene);
app_stage.show();
}
@FXML
private void clearForm() {
LastNameField.clear();
FirstNameField.clear();
DateOfBirthField.clear();
}
}