/** A simple Polygon. @author Charlie McDowell */ class Polygon implements Shape { private int[] x, y; int count = 0; /** Construct a polygon with capacity for the specified number of points. */ Polygon(int size) { x = new int[size]; y = new int[size]; } /** Add a point to this polygon. @throws IndexOutOfBoundsException if this polygon is at capacity */ void add(int x, int y) { if (count >= this.x.length) { throw new IndexOutOfBoundsException("Too many points for this polygon."); } else { this.x[count] = x; this.y[count] = y; count++; } } /** Draw this polygon on the specifid graphics device. */ public void draw(TGraphics graphics) { for(int i = 0; i < x.length-1; i++) { graphics.drawLine(x[i],y[i], x[i+1], y[i+1]); } graphics.drawLine(x[x.length-1],y[y.length-1], x[0], y[0]); } }