Newer
Older
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public Rectangle(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
public void paint(GraphicsContext graphicsContext) {
graphicsContext.strokeRect(x, y, width, height);
@Override
public boolean contains(double x, double y) {
return x>= this.x && x<= this.x + this.width
&& y>= this.y && y<= this.y + this.height;
}
@Override
public void translate(double dx, double dy) {
x += dx;
y += dy;
public void updateSize(double newX, double newY) {
this.width = Math.abs(newX - this.x);
this.height = Math.abs(newY - this.y);
if (newX < this.x && newY < this.y) {
this.x = newX;
this.y = newY;
}
}
public Color getFillColor() {
return fillColor;
}
public void setFinished(boolean finished) {
isFinished = finished;
}
public void setFillColor(Color fillColor) {
this.fillColor = fillColor;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void setDimensions(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = Math.abs(width);
this.height = Math.abs(height);
if(width < 0 ){ this.x += width;}
if(height < 0){ this.y += height;}
}