Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.3 kB
1
Indexable
import java.awt.*;

public class Rectangle extends Shape implements BorderColor, FillColor {
    public Rectangle(int xStart, int yStart, int xEnd, int yEnd, Color borderColor) {
        super(xStart, yStart, xEnd, yEnd, borderColor);
    }


    @Override
    public void drawShape(Graphics g, Point start, Point end) {
        int distX = Math.min(start.x, end.x);
        int distY = Math.min(start.y, end.y);
        int dist1 = Math.abs(start.x - end.x);
        int dist2 = Math.abs(start.y - end.y);

        if(borderColor == null) {
            g.setColor(Color.black);
        }
        else {
            g.setColor(this.borderColor);
        }
        g.drawRect(distX, distY, dist1, dist2);

    }
    @Override
    public boolean contains(Point pointClicked) {
        return (pointClicked.x > startingPoint.x && pointClicked.x < endingPoint.x && pointClicked.y > startingPoint.y && pointClicked.y < endingPoint.y);
    }

    @Override
    public void setBorderColor(Graphics g, Color borderColor){
        g.setColor(borderColor);

    }

    @Override
    public void setFillColor(Graphics g, Color fillColor, Point start, Point end) {
    }

    @Override
    public String toString() {
        return "Rectangle: " + super.toString();
    }

}