Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+33 votes

In the LoginWindowController class, we have a line of code

NextWindowController nextController = loader.getController();.

Can someone explain what it's for cause I can't find where we use it. Thanks.

Rest of code:

public void handleNext() throws IOException  {
	FXMLLoader loader = new FXMLLoader(getClass().getResource("NextWindow.fxml"));
	AnchorPane root = (AnchorPane)loader.load();
	NextWindowController nextController = loader.getController();
	Scene nextScene = new Scene(root,root.getPrefWidth(),root.getPrefHeight());
	Stage primary = (Stage) btnNext.getScene().getWindow();
//		Stage stage = new Stage();
//		stage.setScene(scene);
//		stage.show();		
//		btnNext.getScene().getWindow().hide();
asked in CSC285_Fall2018 by (8 points)
edited by

1 Answer

+15 votes
Best answer

It is used in the line right below: nextController.updateName(textfieldName.getText());
Basically, when we type in the text field, it saves the String that you typed, and load it up on the next scene with the updateName(String). If we didn't have that line, the compiler wouldn't know the reference of the NextWindowController object, thus cannot call the updateName(String) method.

answered by (8 points)
selected by

Lol, thanks. Didn't see that.