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

fix of The Circle class stores the center point and radius, and it implements...

fix of The Circle class stores the center point and radius, and it implements the draw method to render the circle using JavaFX's GraphicsContext.
parent 2a168d27
Branches
No related tags found
No related merge requests found
...@@ -2,24 +2,36 @@ package shape; ...@@ -2,24 +2,36 @@ package shape;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Circle implements Shape { public class Circle implements Shape {
private Point2D center;
private double radius;
private Color color;
public Circle(double x, double y, double sqrt) { public Circle(Color color, double x, double y, double radius) {
this.color = color;
this.center = new Point2D(x, y);
this.radius = radius;
} }
@Override @Override
public int pointsCount() { public int pointsCount() {
return 0; return 1; // Un cercle n'a qu'un centre
} }
@Override @Override
public Point2D point(int index) { public Point2D point(int index) {
return null; if (index == 0) {
return center;
}
throw new IndexOutOfBoundsException("Circle has only one center point.");
} }
@Override @Override
public void draw(GraphicsContext context) { public void draw(GraphicsContext context) {
context.setStroke(color);
context.strokeOval(center.getX() - radius, center.getY() - radius,
radius * 2, radius * 2);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment