/** * Segment.java * * Shows how a Segment class can be built by inheritance. * @author Scot Drysdale on 4/27/00. * Minor modification on 1/21/16. */ import java.awt.*; public class Segment extends GeomShape { private int myX1, myY1, myX2, myY2; // Segment endpoints /** * Constructor for Segment. Called to create a segment object with endpoints * (x1, y1) and (x2, y2), with color segmentColor. * * @param x1 x coordinate of point 1 * @param y1 y coordinate of point 1 * @param x2 x coordinate of point 2 * @param y2 y coordinate of point 2 * @param segmentColor the color of the segment */ public Segment(int x1, int y1, int x2, int y2, Color segmentColor) { super(segmentColor); myX1 = x1; myX2 = x2; myY1 = y1; myY2 = y2; } /** * Have the Segment object draw itself on the page passed as a parameter. * Assumes that the Graphics object's color has already been set. * @page the graphics page on which to draw. */ protected void drawShape(Graphics page) { page.drawLine(myX1, myY1, myX2, myY2); } /** * Move the Segment by deltaX in x and deltaY in y. * deltaX the change in the x values * deltaY the change in the y values */ public void move(int deltaX, int deltaY) { myX1 += deltaX; myX2 += deltaX; myY1 += deltaY; myY2 += deltaY; } /** * A segment has no area. * @return the area of the segment */ public double areaOf() { return 0.0; } }