Skip to content
Snippets Groups Projects
Verified Commit 73867e2b authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Use Java version 17.

Use AnimationTimer instead of common Thread.
parent ed4b8024
Branches
No related merge requests found
......@@ -8,19 +8,19 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
<version>17.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
......
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 timer;
@Override
public void start(Stage primaryStage) {
......@@ -37,25 +38,19 @@ public class App extends Application {
//Exit program when main window is closed
primaryStage.setOnCloseRequest(this::exitProgram);
//Draw scene on a separate thread to avoid blocking UI.
new Thread(this::drawScene).start();
//graphic context is used for a painting
GraphicsContext gc = canvas.getGraphicsContext2D();
timer = new DrawingThread(gc);
timer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Draws objects into the canvas. Put you code here.
*
*@return nothing
*/
private void drawScene() {
//graphic context is used for a painting
GraphicsContext gc = canvas.getGraphicsContext2D();
// put your code here
// gc.setFill(Color.AQUA);
// gc.setStroke(Color.BLACK);
@Override
public void stop() throws Exception {
timer.stop();
super.stop();
}
private void exitProgram(WindowEvent evt) {
......
package lab;
import javafx.animation.AnimationTimer;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class DrawingThread extends AnimationTimer {
private final GraphicsContext gc;
public DrawingThread(GraphicsContext gc) {
this.gc = gc;
}
/**
* Draws objects into the canvas. Put you code here.
*/
@Override
public void handle(long now) {
// put your code here
gc.setFill(Color.AQUA);
gc.setStroke(Color.BLACK);
gc.fillOval(10, 10, 20, 20);
}
}
module lab01 {
requires transitive javafx.controls;
requires javafx.fxml;
requires javafx.base;
opens lab to javafx.fxml;
exports lab;
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment