How to fill color on triangle

前端 未结 3 1190
隐瞒了意图╮
隐瞒了意图╮ 2021-01-05 13:56

I draw a triangle using line. How can I fill color on it? So far I can only success color the line but not fill the color.

public void paintComponent(Graphic         


        
3条回答
  •  生来不讨喜
    2021-01-05 14:28

        public void paintComponent(Graphics g){
             super.paintComponents(g);
    
          int x[] = {1,2,3};
          int y[] = {4,5,6};
          int npoints = x.length;//or y.length
    
          g.drawPolygon(x, y, npoints);//draws polygon outline
          g.fillPolygon(x, y, npoints);//paints a polygon
    
    }
    

提交回复
热议问题