Chapter 11 Graphics and Java2D (Web design course) 625 Fig. 11.19

Chapter 11 Graphics and Java2D 625 Fig. 11.19 Demonstrating drawArcand fillArc(part 3 of 3). 11.7 Drawing Polygons and Polylines Polygons are multisided shapes. Polylines are a series of connected points. Graphics methods for drawing polygons and polylines are discussed in Fig. 11.20. Note that some methods require a Polygon object (package java.awt). Class Polygon s constructors are also described in Fig. 11.20. Method Description public void drawPolygon( int xPoints[], int yPoints[], int points ) Draws a polygon. The x-coordinate of each point is specified in the xPoints array and the y-coordinate of each point is specified in the yPointsarray. The last argument specifies the number of points. This method draws a closed polygon even if the last point is different from the first point. public void drawPolyline( int xPoints[], int yPoints[], int points ) Draws a series of connected lines. The x-coordinate of each point is specified in the xPointsarray and the y-coordinate of each point is specified in the yPointsarray. The last argument specifies the number of points. If the last point is different from the first point, the polyline is not closed. public void drawPolygon( Polygon p ) Draws the specified closed polygon. public void fillPolygon( int xPoints[], int yPoints[], int points ) Draws a solid polygon. The x-coordinate of each point is specified in the xPointsarray and the y-coordinate of each point is specified in the yPoints array. The last argument specifies the number of points. This method draws a closed polygon even if the last point is different from the first point. public void fillPolygon( Polygon p ) Draws the specified solid polygon. The polygon is closed. Fig. 11.20 Graphicsmethods for drawing polygons and class Polygon constructors (part 1 of 2). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply