CJCoding With Joseph
15free / daySign inCreate account
Back to Multiple Choice Quiz

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics

Scene Switching

Java quiz · Question 62
mediumJavaFX

What happens when the "Go to Page 2" button is clicked?

Code

1// Scene 1
2VBox layout1 = new VBox();
3Button goToPage2 = new Button("Go to Page 2");
4layout1.getChildren().add(goToPage2);
5Scene scene1 = new Scene(layout1, 400, 300);
6 
7// Scene 2
8VBox layout2 = new VBox();
9layout2.getChildren().add(new Label("Welcome to Page 2"));
10Scene scene2 = new Scene(layout2, 400, 300);
11 
12goToPage2.setOnAction(e -> primaryStage.setScene(scene2));
13 
14primaryStage.setScene(scene1);
15primaryStage.show();