Select Git revision
Circle.java
Forked from
COUETOUX Basile / graphic-2020
Source project has a limited visibility.
-
AREZKI Celia authored
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.
AREZKI Celia authoredfix of The Circle class stores the center point and radius, and it implements the draw method to render the circle using JavaFX's GraphicsContext.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Circle.java 945 B
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Circle implements Shape {
private Point2D center;
private double radius;
private Color color;
public Circle(Color color, double x, double y, double radius) {
this.color = color;
this.center = new Point2D(x, y);
this.radius = radius;
}
@Override
public int pointsCount() {
return 1; // Un cercle n'a qu'un centre
}
@Override
public Point2D point(int index) {
if (index == 0) {
return center;
}
throw new IndexOutOfBoundsException("Circle has only one center point.");
}
@Override
public void draw(GraphicsContext context) {
context.setStroke(color);
context.strokeOval(center.getX() - radius, center.getY() - radius,
radius * 2, radius * 2);
}
}