Summary
Keywords
Full Transcript
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 root = FXMLLoader.load(getClass().getResource("Scene2.fxml")); stage = (Stage)((Node)event.getSource()).getScene().getWindow(); scene = new Scene(root); stage.setScene(scene); stage.show(); } } //------------------------------------------------------------------------------------------------ Bro Code merch store π : =========================================================== https://teespring.com/stores/bro-code-5 =========================================================== music credits πΌ : =========================================================== Up In My Jam (All Of A Sudden) by - Kubbi https://soundcloud.com/kubbi Creative Commons β Attribution-ShareAlike 3.0 Unportedβ CC BY-SA 3.0 Free Download / Stream: http://bit.ly/2JnDfCE Music promoted by Audio Library https://youtu.be/tDexBj46oNI ===========================================================
