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

Pass canvas to DrawingThread

parent 73867e2b
No related merge requests found
......@@ -38,10 +38,7 @@ public class App extends Application {
//Exit program when main window is closed
primaryStage.setOnCloseRequest(this::exitProgram);
//graphic context is used for a painting
GraphicsContext gc = canvas.getGraphicsContext2D();
timer = new DrawingThread(gc);
timer = new DrawingThread(canvas);
timer.start();
} catch (Exception e) {
e.printStackTrace();
......
package lab;
import javafx.animation.AnimationTimer;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class DrawingThread extends AnimationTimer {
private final Canvas canvas;
private final GraphicsContext gc;
public DrawingThread(GraphicsContext gc) {
this.gc = gc;
public DrawingThread(Canvas canvas) {
this.canvas = canvas;
this.gc = canvas.getGraphicsContext2D();
}
/**
......@@ -18,9 +21,9 @@ public class DrawingThread extends AnimationTimer {
@Override
public void handle(long now) {
// put your code here
gc.setFill(Color.AQUA);
gc.setStroke(Color.BLACK);
gc.fillOval(10, 10, 20, 20);
//gc.setFill(Color.AQUA);
//gc.setStroke(Color.BLACK);
//gc.fillOval(10, 10, 20, 20);
}
......
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