From 3b02b0b76f7550e6ae23da8a74ddc7893487fb6c Mon Sep 17 00:00:00 2001 From: a23022716 <celia.arezki.1@etu.univ-amu.fr> Date: Fri, 27 Sep 2024 11:45:31 +0200 Subject: [PATCH] The ShapeContainer class now correctly adds shapes to a list with the addShape method, and the draw method iterates over the shapes to render them on the canvas. --- src/main/java/shape/Rectangle.java | 2 +- src/main/java/shape/ShapeContainer.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/shape/Rectangle.java b/src/main/java/shape/Rectangle.java index 34b41f8..9dc4a7f 100644 --- a/src/main/java/shape/Rectangle.java +++ b/src/main/java/shape/Rectangle.java @@ -16,7 +16,7 @@ public class Rectangle implements Shape { @Override public int pointsCount() { - return 2; // Un rectangle a 2 points (deux coins opposés) + return 2; } @Override diff --git a/src/main/java/shape/ShapeContainer.java b/src/main/java/shape/ShapeContainer.java index 91c7d29..174f89d 100644 --- a/src/main/java/shape/ShapeContainer.java +++ b/src/main/java/shape/ShapeContainer.java @@ -1,18 +1,20 @@ package shape; import javafx.scene.canvas.GraphicsContext; - import java.util.ArrayList; import java.util.List; -public class ShapeContainer{ +public class ShapeContainer { private List<Shape> shapes = new ArrayList<>(); - public void addShape(Shape shape){} + public void addShape(Shape shape) { + shapes.add(shape); + } - public void draw(GraphicsContext context){ - for(Shape shape : shapes) + public void draw(GraphicsContext context) { + for (Shape shape : shapes) { shape.draw(context); + } } } -- GitLab