tubeshowcase●1,194,391 videos♡ My collection 0
← Learn to Code

Learn to Code08:35

JavaFX switch scenes 💞

Bro Code ↗

From the creator

JavaFX switch scenes with using SceneBuilder tutorial example explained #javafx #switch #scenes //--------------------------------Main.java-------------------------------------- package application; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.stage.Stage; import javafx.scene.Parent; import javafx.scene.Scene; public class Main extends Application { @Override public void start(Stage stage) { try { Parent root = FXMLLoader.load(getClass().getResource("Scene1.fxml")); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } } //---------------------------------SceneController.java--------------------------------------- package application; import java.io.IOException; import javafx.event.ActionEvent; import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class SceneController { private Stage stage; private Scene scene; private Parent root; public void switchToScene1(ActionEvent event) throws IOException { root = FXMLLoader.load(getClass().getResource("Scene1.fxml")); stage = (Stage)((Node)event.getSource()).getScene().getWindow(); scene = new Scene(root); stage.setScene(scene); stage.show(); } public void switchToScene2(ActionEvent event) throws IOException { Parent r

Published 2021-01-11 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code