Advertisement
sergAccount

Untitled

Oct 4th, 2020
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. package com.spec.ui;
  2.  
  3. import javafx.application.Application;
  4. import javafx.fxml.FXMLLoader;
  5. import javafx.scene.Parent;
  6. import javafx.scene.Scene;
  7. import javafx.stage.Stage;
  8.  
  9. import java.io.IOException;
  10.  
  11. /**
  12.  * JavaFX App
  13.  */
  14. public class App extends Application {
  15.  
  16.     private static Scene scene;
  17.  
  18.     @Override
  19.     public void start(Stage stage) throws IOException {
  20.         scene = new Scene(loadFXMLWithController("primary"), 640, 480);
  21.         stage.setScene(scene);
  22.         stage.show();
  23.     }
  24.  
  25.     static void setRoot(String fxml) throws IOException {
  26.         scene.setRoot(loadFXML(fxml));
  27.     }
  28.  
  29.     private static Parent loadFXML(String fxml) throws IOException {
  30.         FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));                        
  31.         // use setController
  32.         fxmlLoader.setController(new PrimaryController());
  33.         return fxmlLoader.load();
  34.     }
  35.     //
  36.     private static Parent loadFXMLWithController(String fxml) throws IOException {
  37.         FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));                        
  38.         // use setController
  39.         fxmlLoader.setController(new PrimaryController());        
  40.         Parent p = fxmlLoader.load();
  41.         return p;
  42.     }
  43.  
  44.     public static void main(String[] args) {
  45.         launch();
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement