Alright, I have been reading a lot of stackoverflow posts about how to PROPERLY create a JavaFX application with two windows that share data between them I can't find any clear solution. This is my current solution, basically creating a reference to the other controller which is really bad practice.
Would it be good practice to create a Model that is shared between the two controllers? If so how would I inject the Model object into the controllers when they dont have any constructors?
public class ControllerOne implements Initializable {
@FXML private TextField textField;
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@FXML
private void handleButtonAction(ActionEvent event) {
if(textField.getText().equals("")){
}
else{
System.out.println(textField.getText());
String itemNumber = textField.getText();
Main.getControllerTwo().setLabel(itemNumber);
textField.setText("");
textField.requestFocus();
}
}
}
Second window
public class ControllerTwo implements Initializable {
@FXML
private Label itemLabel;
@Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
}
public void setLabel(String itemNumber){
itemLabel.setText(itemNumber);
}
public Label getLabel(){
return itemLabel;
}
}