From 3175d3502a5bb0c1fe4a66191cb7079b1a5cb6e5 Mon Sep 17 00:00:00 2001 From: Chadi <130995657+PayneKev@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:06:54 +0200 Subject: [PATCH] need to check in uni --- src/main/java/shape/Circle.java | 36 +++++++++++++++++++++--------- src/main/java/shape/Drawer.java | 8 +++---- src/main/java/shape/Rectangle.java | 28 ++++++++++++++--------- src/main/java/shape/Shape.java | 1 - 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/main/java/shape/Circle.java b/src/main/java/shape/Circle.java index 503f9b2..3c2060c 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 58dee9e..76f3360 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 0fb3372..b57f9df 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 1cd8240..98f44a7 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); } -- GitLab