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