diff --git a/pom.xml b/pom.xml index a3464194e11d8ff05f706209219b18b253d9ed34..53a059ee66a70ef50dbbb866e904112f2ae64eb3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>vsb-cs-java1</groupId> - <artifactId>lab01</artifactId> + <artifactId>lab02</artifactId> <version>0.0.1-SNAPHOST</version> <packaging>jar</packaging> <properties> diff --git a/src/main/java/lab/App.java b/src/main/java/lab/App.java index a978898122d31d1146ae90070389ca68f5913cfd..2fa95e3778cd4d5ae9c8b32a9f4fd7044224ea30 100644 --- a/src/main/java/lab/App.java +++ b/src/main/java/lab/App.java @@ -1,7 +1,7 @@ package lab; +import javafx.animation.AnimationTimer; import javafx.application.Application; -import javafx.application.Platform; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; @@ -20,6 +20,7 @@ public class App extends Application { } private Canvas canvas; + private AnimationTimer animationTimer; @Override public void start(Stage primaryStage) { @@ -32,14 +33,28 @@ public class App extends Application { scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.resizableProperty().set(false); - primaryStage.setTitle("Java 1 - 1th laboratory"); + primaryStage.setTitle("Java 1 - 2nd laboratory"); primaryStage.show(); - //Exit program when main window is closed - primaryStage.setOnCloseRequest(this::exitProgram); + //Draw scene on a separate thread to avoid blocking UI. - Platform.runLater(this::drawScene); + animationTimer = new AnimationTimer() { + private Long previous; + + @Override + public void handle(long now) { + if (previous == null) { + previous = now; + } else { + drawScene((now - previous)/1e9); + previous = now; + } + } + }; + animationTimer.start(); + //Exit program when main window is closed + primaryStage.setOnCloseRequest(this::exitProgram); } catch (Exception e) { e.printStackTrace(); } @@ -50,15 +65,14 @@ public class App extends Application { * *@return nothing */ - private void drawScene() { + private void drawScene(double deltaT) { //graphic context is used for a painting GraphicsContext gc = canvas.getGraphicsContext2D(); - // put your code here - // gc.setFill(Color.AQUA); - // gc.setStroke(Color.BLACK); + } private void exitProgram(WindowEvent evt) { + animationTimer.stop(); System.exit(0); } } \ No newline at end of file diff --git a/src/main/resources/lab/fireball-transparent.gif b/src/main/resources/lab/fireball-transparent.gif new file mode 100644 index 0000000000000000000000000000000000000000..ed734a665d6208de17057a378b4d4520126301b5 Binary files /dev/null and b/src/main/resources/lab/fireball-transparent.gif differ