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

fix of The Rectangle class who implements the draw method to render the...

fix of The Rectangle class who implements the draw method to render the rectangle using JavaFX's GraphicsContext
parent 54904bc7
Branches
No related tags found
No related merge requests found
......@@ -5,23 +5,35 @@ import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Rectangle implements Shape {
Color color;
Rectangle(Color color, Point2D point0, Point2D point1){
private Color color;
private Point2D point0, point1;
public Rectangle(Color color, Point2D point0, Point2D point1) {
this.color = color;
this.point0 = point0;
this.point1 = point1;
}
@Override
public int pointsCount() {
return 0;
return 2; // Un rectangle a 2 points (deux coins opposés)
}
@Override
public Point2D point(int index) {
return null;
if (index == 0) {
return point0;
} else if (index == 1) {
return point1;
}
throw new IndexOutOfBoundsException("Rectangle has only 2 points.");
}
@Override
public void draw(GraphicsContext context) {
context.setStroke(color);
context.strokeRect(point0.getX(), point0.getY(),
point1.getX() - point0.getX(),
point1.getY() - point0.getY());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment