Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+34 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 (1 point)
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 (1 point)
selected by
+5

Lol, thanks. Didn't see that.

...