-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloFX.java
More file actions
54 lines (40 loc) · 1.54 KB
/
HelloFX.java
File metadata and controls
54 lines (40 loc) · 1.54 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
package com.example;
import io.github.cdimascio.dotenv.Dotenv;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.util.Objects;
public class HelloFX extends Application {
@Override
public void start(Stage stage) throws Exception {
Dotenv dotenv = Dotenv.load(); //Ladda .env-filen
String hostName = dotenv.get("HOST_NAME");
//Validering (valfritt)
if (hostName == null) {
throw new IllegalStateException(
"Kunde inte läsa HOST_NAME från .env-filen. " +
"Kontrollera att filen finns i projektets rotmapp!"
);
}
System.out.println("Ansluter till ntfy på: " + hostName); //Debug-logg
HelloModel model = new HelloModel();
ChatNetworkClient httpClient = new NtfyHttpClient();
FXMLLoader fxmlLoader = new FXMLLoader(
HelloFX.class.getResource("/com/example/hello-view.fxml")
);
fxmlLoader.setControllerFactory(c -> new HelloController(model, httpClient, hostName));
Parent root = fxmlLoader.load();
Scene scene = new Scene(root, 640, 480);
scene.getStylesheets().add(
Objects.requireNonNull(getClass().getResource("/com/example/styles.css")).toExternalForm()
);
stage.setTitle("Chat App");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}