Untitled

 avatar
unknown
plain_text
3 years ago
2.0 kB
6
Indexable
import java.awt.*;
import java.io.Serializable;

public abstract class Shape implements Serializable {
    protected Point startingPoint;
    protected Point endingPoint;
    protected Color borderColor;


    public Shape(int xStart, int yStart, int xEnd, int yEnd, Color borderColor) {
        startingPoint = new Point(xStart, yStart);
        endingPoint = new Point(xEnd, yEnd);
        this.borderColor = borderColor;

    }

//    public void setPosition(int x, int y, int pointNumber) {
//        points[pointNumber].x = x;
//        points[pointNumber].y = y;//ask
//    }
//
//    public void setStart(int xStart, int yStart) {
//        points[0].x = xStart;
//        points[0].y = yStart;
//    }
//
//    public void setEnd(int xEnd, int yEnd) {
//        points[1].x = xEnd;
//        points[1].y = yEnd;
//    }
    public abstract boolean contains(Point pointClicked);

    public double calculate(Point startingPoint, Point endingPoint) {
        return Math.sqrt((startingPoint.x - endingPoint.x) * (startingPoint.x  - endingPoint.x)
                + (startingPoint.y  - endingPoint.y) * (startingPoint.y - endingPoint.y));
    }

    //
    public abstract void drawShape(Graphics g, Point startingPoint, Point endingPoint);

    @Override
    public String toString() {
        //return Arrays.toString(points) + "";//returning an array of objects to string
        return "Point[0].x: " + startingPoint.x + " Point[0].y: "  + startingPoint.y + " Point[1].x: " + endingPoint.x + " Point[1].y: " + endingPoint.y + "\n";
    }

//    public boolean shouldDelete(Point location){
//        return (location.x > startingPoint.x && location.y > startingPoint.y && location.x< endingPoint.x && location.y < endingPoint.y) ||
//                (location.x < startingPoint.x && location.y < startingPoint.y && location.x> endingPoint.x && location.y > endingPoint.y);
//
//    }

}

Editor is loading...