Skip to content
Snippets Groups Projects
Commit 3175d350 authored by Chadi's avatar Chadi
Browse files

need to check in uni

parent bc3215f2
No related branches found
No related tags found
No related merge requests found
...@@ -13,16 +13,16 @@ public class Circle implements Shape { ...@@ -13,16 +13,16 @@ public class Circle implements Shape {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.radius = radius; this.radius = radius;
this.fillColor = Color.GREEN; this.isFinished = true;
this.isFinished = false;
} }
@Override @Override
public void paint(GraphicsContext graphicsContext) { public void paint(GraphicsContext graphicsContext) {
graphicsContext.setStroke(Color.BLACK); graphicsContext.setStroke(Color.BLACK);
graphicsContext.setLineWidth(2);
if (isFinished) { if (isFinished) {
graphicsContext.setFill(fillColor); graphicsContext.setFill(Color.GREEN);
graphicsContext.fillOval(x - radius, y - radius, 2 * radius, 2 * radius); 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);
...@@ -46,12 +46,28 @@ public class Circle implements Shape { ...@@ -46,12 +46,28 @@ public class Circle implements Shape {
return isFinished; return isFinished;
} }
@Override public void setX(double x) {
public void setFillColor(Color fillColor) { this.x = x;
this.fillColor = fillColor; }
public void setY(double y) {
this.y = y;
}
public void setFinished(boolean finished) {
isFinished = finished;
} }
public void updateRadius(double newX, double newY) { 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;
}
} }
...@@ -75,13 +75,11 @@ public class Drawer { ...@@ -75,13 +75,11 @@ public class Drawer {
if(event.getButton() == MouseButton.PRIMARY && tempShape != null){ if(event.getButton() == MouseButton.PRIMARY && tempShape != null){
shapes.add(tempShape); shapes.add(tempShape);
if (tempShape instanceof Rectangle){ if (tempShape instanceof Rectangle){
tempShape.setFillColor(((Rectangle) tempShape).fillColor); ((Rectangle) tempShape).setFinished(true);
tempShape.isFinished();
}else if (tempShape instanceof Circle){ }else if (tempShape instanceof Circle){
tempShape.setFillColor(((Circle) tempShape).fillColor);
tempShape.isFinished(); ((Circle) tempShape).setFinished(true);
} }
isFinished = true;
repaint(); repaint();
tempShape = null; tempShape = null;
} }
......
...@@ -6,26 +6,24 @@ import javafx.scene.paint.Color; ...@@ -6,26 +6,24 @@ import javafx.scene.paint.Color;
public class Rectangle implements Shape{ public class Rectangle implements Shape{
private double x; private double x,y,width, height;
private double y;
private double width;
private double height;
private boolean isFinished; private boolean isFinished;
public Color fillColor = Color.RED; public Color fillColor;
public Rectangle(double x, double y, double width, double height) { public Rectangle(double x, double y, double width, double height) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.width = width; this.width = width;
this.height = height; this.height = height;
this.isFinished = false; this.isFinished = true;
} }
@Override @Override
public void paint(GraphicsContext graphicsContext) { public void paint(GraphicsContext graphicsContext) {
graphicsContext.setStroke(Color.BLACK); graphicsContext.setStroke(Color.BLACK);
graphicsContext.setLineWidth(2);
if(isFinished){ if(isFinished){
graphicsContext.setFill(fillColor); graphicsContext.setFill(Color.RED);
graphicsContext.fillRect(x, y, width, height); graphicsContext.fillRect(x, y, width, height);
} }
graphicsContext.strokeRect(x, y, width, height); graphicsContext.strokeRect(x, y, width, height);
...@@ -49,10 +47,6 @@ public class Rectangle implements Shape{ ...@@ -49,10 +47,6 @@ public class Rectangle implements Shape{
return isFinished; return isFinished;
} }
@Override
public void setFillColor(Color fillColor) {
this.fillColor = fillColor;
}
public void updateSize(double newX, double newY) { public void updateSize(double newX, double newY) {
this.width = Math.abs(newX - this.x); this.width = Math.abs(newX - this.x);
...@@ -62,4 +56,16 @@ public class Rectangle implements Shape{ ...@@ -62,4 +56,16 @@ public class Rectangle implements Shape{
this.y = newY; this.y = newY;
} }
} }
public Color getFillColor() {
return fillColor;
}
public void setFinished(boolean finished) {
isFinished = finished;
}
public void setFillColor(Color fillColor) {
this.fillColor = fillColor;
}
} }
...@@ -9,5 +9,4 @@ public interface Shape { ...@@ -9,5 +9,4 @@ public interface Shape {
boolean contains(double x, double y); boolean contains(double x, double y);
void translate(double dx, double dy); void translate(double dx, double dy);
boolean isFinished(); boolean isFinished();
void setFillColor(Color fillColor);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment