62 lines
1.9 KiB
Java
62 lines
1.9 KiB
Java
package fr.alnotz.gui;
|
|
|
|
import javafx.application.Application;
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.input.KeyEvent;
|
|
import javafx.scene.layout.Pane;
|
|
import javafx.stage.Stage;
|
|
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import java.nio.file.FileSystems;
|
|
|
|
|
|
/**
|
|
* JavaFX App
|
|
*/
|
|
public class App extends Application {
|
|
/**
|
|
* JavaFX starter
|
|
* @param stage Main stage
|
|
* @throws IOException In/Out exception
|
|
*/
|
|
@Override
|
|
public void start(Stage stage) throws IOException {
|
|
///// Scene and style added /////
|
|
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 Pane pane = fxmlLoader.load();
|
|
final Scene scene = new Scene(pane,800,600);
|
|
final String cssStr =
|
|
"file:src/main/resources/fr/alnotz/style/mainStyle.css";
|
|
scene.getStylesheets().add(cssStr);
|
|
stage.setScene(scene);
|
|
///// Stage loaded and events listened /////
|
|
stage.setTitle("Main window");
|
|
final String imgPath =
|
|
"file:src/main/resources/fr/alnotz/alnotz.png";
|
|
stage.getIcons().add(new Image(imgPath));
|
|
stage.addEventHandler(KeyEvent.KEY_PRESSED, keyEvent ->
|
|
System.out.println("Key pressed (code): " +
|
|
keyEvent.getCode().getCode())
|
|
);
|
|
stage.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent ->
|
|
System.out.println("Key released (code): " +
|
|
keyEvent.getCode().getCode())
|
|
);
|
|
stage.show();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
launch();
|
|
}
|
|
|
|
} |