Tuesday, November 4, 2008

DrawPoly

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

// This applet draws a polygon using an array of points

public class DrawPoly extends Applet{

// Define an array of X coordinates for the polygon
int xCoords[] = { 10, 40, 60, 30, 10 };

// Define an array of Y coordinates for the polygon
int yCoords[] = { 20, 0, 10, 60, 40 };

public void paint(Graphics g) {

// 5 points in polygon
g.drawPolygon(xCoords, yCoords, 5);

}

}