111 Program to draw and fill Polygon in Java

Code:

/* Program to draw and fill Polygon */

import java.awt.*;
import java.applet.*;

public class Polygon extends Applet
{
public void paint(Graphics g)
{
int xpoints[] = {30,200,30,200,30};
int ypoints[] = {30,30,200,200,30};
int num = 5;

g.drawPolygon(xpoints,ypoints,num);
g.setColor(Color.red);
g.fillPolygon(xpoints,ypoints,num);

}

}

/*
<applet code="Polygon" height=400 width=400>
</applet>
*/



Ouput:

draw and fill Polygon in Java

Previous
Next Post »