import java.util.ArrayList; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; public class MyCanvas extends Canvas { private double width, height; // Canvas has them, as private private GraphicsContext gc; // Canvas has it, as private private ArrayList strokes; public MyCanvas(double w, double h) { super(w, h); width = w; height = h; gc = super.getGraphicsContext2D(); strokes = new ArrayList<>(); } public void addStroke(Stroke s) { strokes.add(s); // must repaint paint(); } public void clearCanvas() { strokes.clear(); paint(); } public void paint() { // clear canvas gc.clearRect(0, 0, width, height); // draw all strokes in the arraylist for (Stroke s : strokes) { s.draw(gc); } } }