import objectdraw.*; import java.awt.Color; // a class representing all the components of a basketball public class Basketball { private static final Color BALL_ORANGE = new Color(250, 85, 10); // the interior of the ball private FilledOval body; // black frame around the ball private FramedOval border; // size and starting angles for cut arc in degrees private static final int CUTSIZE = 100; private static final int RIGHTCUTSTART = 90 + (180 - CUTSIZE) / 2; private static final int LEFTCUTSTART = 270 + (180 - CUTSIZE) / 2; // the two curves on the sides of the ball private FramedArc leftCut, rightCut; // the vertical and horizontal lines through the ball private Line vert, horiz; private double startingX; private double startingY; public Basketball(double xcoord, double ycoord, double size, DrawingCanvas canvas) { startingX = xcoord; startingY = ycoord; body = new FilledOval(xcoord, ycoord, size, size, canvas); border = new FramedOval(xcoord, ycoord, size, size, canvas); // draw the lines and arcs that make it look like a basketball rightCut = new FramedArc(xcoord + size * 2 / 3, ycoord, size, size, RIGHTCUTSTART, CUTSIZE, canvas); leftCut = new FramedArc(xcoord - size * 2 / 3, ycoord, size, size, LEFTCUTSTART, CUTSIZE, canvas); vert = new Line( xcoord + size / 2, ycoord, xcoord + size / 2, ycoord + size, canvas); horiz = new Line( xcoord, ycoord + size / 2, xcoord + size, ycoord + size / 2, canvas); body.setColor(BALL_ORANGE); } public void move(double changeInX, double changeInY) { body.move(changeInX, changeInY); border.move(changeInX, changeInY); rightCut.move(changeInX, changeInY); leftCut.move(changeInX, changeInY); vert.move(changeInX, changeInY); horiz.move(changeInX, changeInY); } public boolean contains(Location point) { return body.contains(point); } public double getX() { return body.getX(); } public double getY() { return body.getY(); } public void returnToStart() { this.move(startingX - this.getX(), startingY - this.getY()); } }