Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.spec.ui;
- import javafx.application.Application;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.stage.Stage;
- import java.io.IOException;
- /**
- * JavaFX App
- */
- public class App extends Application {
- private static Scene scene;
- @Override
- public void start(Stage stage) throws IOException {
- scene = new Scene(loadFXMLWithController("primary"), 640, 480);
- stage.setScene(scene);
- stage.show();
- }
- static void setRoot(String fxml) throws IOException {
- scene.setRoot(loadFXML(fxml));
- }
- private static Parent loadFXML(String fxml) throws IOException {
- FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
- // use setController
- fxmlLoader.setController(new PrimaryController());
- return fxmlLoader.load();
- }
- //
- private static Parent loadFXMLWithController(String fxml) throws IOException {
- FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
- // use setController
- fxmlLoader.setController(new PrimaryController());
- Parent p = fxmlLoader.load();
- return p;
- }
- public static void main(String[] args) {
- launch();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement