Draw a Polygon in Java Applet

import java.awt.*;
import java.applet.*;
public class polygon extend 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)
{
 g.drawPolygon(a1,b1,n1);
 g.fillPolygon(a2,b2,n2);
}
}

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

Recommended Posts:

Advanced Java
1. Java Applet
2. Applet Life Cycle in Java
3. Difference Between Applet and Application
4. Creating an Executable Applet in Java
5. Displaying Numerical values in Applet
6. An Applet Program to Add Two Numbers
7. Event Handling in Applet
8. AWT Event Classes
9. AWT Graphics Class
10. Draw a line and rectangle in Java Applet
11. Draw Circles and Ellipses in Java Applet
12. Draw a Polygon in Java Applet
13. AWT Hierarchy | AWT Package
14. Swing in Core Java