Draw a Polygon in Java Applet

Polygon in Java Applet

Polygons are shapes with many sides. It may be considered a set of lines connected. The end of the first line is the beginning of the second line, the end of the second is the beginning of the third, and so on. It suggests that we can draw a polygon with n sides using the drawLine() method n times in succession.

We can draw polygons more conveniently using the drawPolygon() method of Graphics class. This method takes three arguments:

1. An array of integers containing x coordinates.
2. An array of integers containing y coordinates.
3. An integer for the total number of points.

Example:

 

Output:
Draw a Polygon in Java Applet