Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
JavaFX switch scenes πŸ’ž
Play lesson

JavaFX - JavaFX switch scenes πŸ’ž

5.0 (2)
47 learners

What you'll learn

This course includes

  • 4.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

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 ===========================================================

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere