Draw a Polygon in Java Applet

Polygons are shapes with many sides. A polygon may be considered a set of lines connected together. 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.


import java.awt.*;
import java.applet.*;
public class polygon extends Applet
 int a1[]={20, 120, 220, 20};
 int b1[]={20, 120, 20, 20};
 int n1=4;
 int a2[]= {120, 220, 220, 120};
 int b2[]= {120, 20, 220, 120};
 int n2=4;
public void paint(Graphics g)

         <applet code = "polygon.class" width = "600" height = "400"></applet>