-
Notifications
You must be signed in to change notification settings - Fork 92
/
FXMLExample.java
42 lines (32 loc) · 1.22 KB
/
FXMLExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.jenkov.javafx.fxml;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.stage.Stage;
import java.io.File;
import java.net.URL;
public class FXMLExample extends Application{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
MyFxmlController controller = new MyFxmlController();
controller.setValue("New value");
loader.setController(controller);
File fxmlFile = new File("assets/fxml/hello-world.fxml");
URL fxmlUrl = fxmlFile.toURI().toURL();
loader.setLocation(fxmlUrl);
VBox vbox = loader.<VBox>load();
MyFxmlController controllerRef = loader.getController();
System.out.println(controllerRef.getValue());
System.out.println(controllerRef.getLabel1Text());
System.out.println(controllerRef.getLabel2Text());
Scene scene = new Scene(vbox);
primaryStage.setScene(scene);
primaryStage.show();
}
}