jfxui/src/main/java/fr/alnotz/gui/App.java
2023-07-08 19:09:36 +02:00

52 lines
1.5 KiB
Java

package fr.alnotz.gui;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import java.nio.file.FileSystems;
/**
* JavaFX App
*/
public class App extends Application {
@Override
public void start(Stage stage) throws IOException {
final String pathStr =
"src/main/resources/fr/alnotz/view/mainView.fxml";
final URL url = FileSystems
.getDefault()
.getPath(pathStr)
.toUri()
.toURL();
final FXMLLoader fxmlLoader = new FXMLLoader(url);
final VBox vbox = fxmlLoader.load();
final Scene scene = new Scene(vbox,640,480);
final String cssStr =
"file:src/main/resources/fr/alnotz/style/mainStyle.css";
scene.getStylesheets().add(cssStr);
stage.setTitle("Main window");
stage.setScene(scene);
stage.addEventHandler(KeyEvent.KEY_PRESSED, keyEvent ->
System.out.println("Key pressed: " +
keyEvent.getCode().getChar())
);
stage.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent ->
System.out.println("Key released: " +
keyEvent.getCode().getChar())
);
stage.show();
}
public static void main(String[] args) {
launch();
}
}