I have my MainView
class, which is the one that starts up the whole program.
public class MainView extends Application {
@Override
public void start(Stage stage) throws IOException {
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent t) {
Platform.exit();
System.exit(0);
}
});
FXMLLoader loader = new FXMLLoader(getClass().getResource("NavigationView.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root);
stage.setResizable(false);
stage.setScene(scene);
stage.show();
stage.setTitle("Greenhouse");
}
/**
* @param args the command line arguments
* @throws java.sql.SQLException
*/
public static void main(String[] args) throws SQLException {
launch(args);
}
}
This class loads my FXML
and starts the program as you probably know. The controller is specified inside the FXML
. Now what I want, is to be able to make a reference to this controller from any class in my program. That is because I want all my System.out.prints
in every class to print out to my TextArea
that is in my controller. This is the TextArea
in my controller:
@FXML
private TextArea GUIprint;
So my question is, how do I make the right reference to my controller, so I can use it in all classes? I know that just making an instance of the controller in other classes would just give me a NullPointerException
.
If you need to see my Initialize
method in my controller, here it is, it just tells what pane to be visible at startup:
@Override
public void initialize(URL url, ResourceBundle rb) {
loginPane.setVisible(true);
}