Friday, March 26, 2010

Other Java Polygon Sample

We can practically draw any shape. I have the sample program below that shows a big octagon as a road sign. Also, we can copy sections of our graphics area by using copyArea method.

See the program below that displays copying of the rectangle to another area. I wish to draw the  text size to be bigger to go with the octagon's size. But we can always resize all these to bigger or smaller ones.

[+/-] show/hide

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

public class GraphicsPolygons extends Applet {
int xPoints[]={200,100,100,200,300,400,400,300};
int yPoints[]={100,200,300,400,400,300,200,100};
int size=xPoints.length;
Color newColor=new Color(.80F,1F,.50F);

public void init()


public void paint(Graphics g)

g.fillPolygon(xPoints,yPoints,xPoints.length); //to fill a solid polygon
g.drawString("STOP", 250, 250);

No comments: