diff --git a/src/main/java/shape/Circle.java b/src/main/java/shape/Circle.java index 503f9b2efa48599949747ef66e285de52f762760..3c2060c6ea9a1adacfe65aa378facbe9844d6295 100644 --- a/src/main/java/shape/Circle.java +++ b/src/main/java/shape/Circle.java @@ -13,26 +13,26 @@ public class Circle implements Shape { this.x = x; this.y = y; this.radius = radius; - this.fillColor = Color.GREEN; - this.isFinished = false; + this.isFinished = true; } @Override public void paint(GraphicsContext graphicsContext) { graphicsContext.setStroke(Color.BLACK); - if(isFinished) { - graphicsContext.setFill(fillColor); + graphicsContext.setLineWidth(2); + if (isFinished) { + graphicsContext.setFill(Color.GREEN); graphicsContext.fillOval(x - radius, y - radius, 2 * radius, 2 * radius); } - graphicsContext.strokeOval(x-radius, y-radius, 2 * radius, 2 * radius); + graphicsContext.strokeOval(x - radius, y - radius, 2 * radius, 2 * radius); } @Override public boolean contains(double x, double y) { double dx = x - this.x; double dy = y - this.y; - return Math.sqrt(dx*dx + dy*dy) <= radius; + return Math.sqrt(dx * dx + dy * dy) <= radius; } @Override @@ -46,12 +46,28 @@ public class Circle implements Shape { return isFinished; } - @Override - public void setFillColor(Color fillColor) { - this.fillColor = fillColor; + public void setX(double x) { + this.x = x; + } + + public void setY(double y) { + this.y = y; + } + + public void setFinished(boolean finished) { + isFinished = finished; } public void updateRadius(double newX, double newY) { - this.radius = Math.sqrt(Math.pow(newX - this.x, 2) + Math.pow(newY - this.y, 2)); + this.radius = Math.sqrt(Math.pow(newX - this.x, 2) + Math.pow(newY - this.y, 2)); + } + + public double getX() { + return x; } + + public double getY() { + return y; + } + } diff --git a/src/main/java/shape/Drawer.java b/src/main/java/shape/Drawer.java index 58dee9e66ece08ac66b84e12d378b1cc4aeec9de..76f336029488d9e0835d1f15244fae894d2d19f3 100644 --- a/src/main/java/shape/Drawer.java +++ b/src/main/java/shape/Drawer.java @@ -75,13 +75,11 @@ public class Drawer { if(event.getButton() == MouseButton.PRIMARY && tempShape != null){ shapes.add(tempShape); if (tempShape instanceof Rectangle){ - tempShape.setFillColor(((Rectangle) tempShape).fillColor); - tempShape.isFinished(); + ((Rectangle) tempShape).setFinished(true); }else if (tempShape instanceof Circle){ - tempShape.setFillColor(((Circle) tempShape).fillColor); - tempShape.isFinished(); + + ((Circle) tempShape).setFinished(true); } - isFinished = true; repaint(); tempShape = null; } diff --git a/src/main/java/shape/Rectangle.java b/src/main/java/shape/Rectangle.java index 0fb33727023023b8091fba96bb7f0fdde9281e96..b57f9dfdc85e91bbdc2e82f97d8570b17ad70507 100644 --- a/src/main/java/shape/Rectangle.java +++ b/src/main/java/shape/Rectangle.java @@ -6,26 +6,24 @@ import javafx.scene.paint.Color; public class Rectangle implements Shape{ - private double x; - private double y; - private double width; - private double height; + private double x,y,width, height; private boolean isFinished; - public Color fillColor = Color.RED; + public Color fillColor; public Rectangle(double x, double y, double width, double height) { this.x = x; this.y = y; this.width = width; this.height = height; - this.isFinished = false; + this.isFinished = true; } @Override public void paint(GraphicsContext graphicsContext) { graphicsContext.setStroke(Color.BLACK); + graphicsContext.setLineWidth(2); if(isFinished){ - graphicsContext.setFill(fillColor); + graphicsContext.setFill(Color.RED); graphicsContext.fillRect(x, y, width, height); } graphicsContext.strokeRect(x, y, width, height); @@ -49,10 +47,6 @@ public class Rectangle implements Shape{ return isFinished; } - @Override - public void setFillColor(Color fillColor) { - this.fillColor = fillColor; - } public void updateSize(double newX, double newY) { this.width = Math.abs(newX - this.x); @@ -62,4 +56,16 @@ public class Rectangle implements Shape{ this.y = newY; } } + + public Color getFillColor() { + return fillColor; + } + + public void setFinished(boolean finished) { + isFinished = finished; + } + + public void setFillColor(Color fillColor) { + this.fillColor = fillColor; + } } diff --git a/src/main/java/shape/Shape.java b/src/main/java/shape/Shape.java index 1cd824056fd91a940ac735cdf69355ce8a059fb9..98f44a7342664012421c4c93d0cf5e461202623a 100644 --- a/src/main/java/shape/Shape.java +++ b/src/main/java/shape/Shape.java @@ -9,5 +9,4 @@ public interface Shape { boolean contains(double x, double y); void translate(double dx, double dy); boolean isFinished(); - void setFillColor(Color fillColor); }