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.

Categories

+32 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:

@FXML
public void handleNext() throws IOException  {
	FXMLLoader loader = new FXMLLoader(getClass().getResource("NextWindow.fxml"));
	AnchorPane root = (AnchorPane)loader.load();
	NextWindowController nextController = loader.getController();
	nextController.updateName(textfieldName.getText());
	
	Scene nextScene = new Scene(root,root.getPrefWidth(),root.getPrefHeight());
	nextScene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
	
	Stage primary = (Stage) btnNext.getScene().getWindow();
	primary.setScene(nextScene);
	
//		Stage stage = new Stage();
//		stage.setScene(scene);
//		stage.show();		
//		btnNext.getScene().getWindow().hide();
	
	//primaryStage.setScene(scene);
	//primaryStage.show();
	
	
}
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
+5

Lol, thanks. Didn't see that.

...