Skip to content
Snippets Groups Projects
Commit d2bea445 authored by AREZKI Celia's avatar AREZKI Celia
Browse files

add Drawer class that manages the shapes wich extends Canvas (javafx class)

parent 969c7ee4
No related branches found
No related tags found
No related merge requests found
package shape.tp5;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import java.util.ArrayList;
import java.util.List;
public class Drawer extends Canvas {
private List<Shape> shapes;
public Drawer(double width, double height) {
super(width, height);
shapes = new ArrayList<>();
}
public void add(Shape shape) {
shapes.add(shape);
repaint();
}
public void repaint() {
GraphicsContext gc = getGraphicsContext2D();
gc.clearRect(0, 0, getWidth(), getHeight());
for (Shape shape : shapes) {
shape.paint(gc);
}
}
public Shape shapeContaining(double x, double y) {
for (Shape shape : shapes) {
if (shape.contains(x, y)) {
return shape;
}
}
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment