如何在三角形上填充颜色
我用线画一个三角形。如何填充颜色?到目前为止,我只能为线条成功上色,而不能填充颜色。
public void paintComponent(Graphics g){        super.paintComponents(g);
        int k=0;
        for (j=0 ; j < numOfLines; j++){    // the values of numOfLines retrieved from other method.
        g.setColor(Color.green);
        g.drawLine(x[k], x[k+1], x[k+2], x[k+3]);
        k = k+4;  //index files
        }
回答:
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.
以上是 如何在三角形上填充颜色 的全部内容, 来源链接: utcz.com/qa/417979.html

