做一个Polygon
从顶点和填充,而不是通过调用fillPolygon(...)
:
// A simple triangle. x[0]=100; x[1]=150; x[2]=50; y[0]=100; y[1]=150; y[2]=150; n = 3; Polygon p = new Polygon(x, y, n); // This polygon represents a triangle with the above // vertices. g.fillPolygon(p); // Fills the triangle above.
您需要指定多边形的顶点(在本例中为三角形)并传递给 fillPolygon():
public void paint(Graphics g) { int xpoints[] = {25, 145, 25, 145, 25}; int ypoints[] = {25, 25, 145, 145, 25}; int npoints = 5; g.fillPolygon(xpoints, ypoints, npoints); }