【发布时间】:2016-11-08 22:40:37
【问题描述】:
所以我得到了这是一个三角形,但我该如何着色呢?我是 Java 新手,所以请耐心等待。我还想稍后复制它并将其粘贴到它旁边,然后在它的头上旋转它。我正在尝试构建的图形是Kite(如您所见,它主要构建在 traingles 的不同部分)。
public void paintComponent(Graphics g) {
super.paintComponent(g);
this.setBackground(Color.yellow);
//this is where the triangle starts
g.setColor(Color.RED);
g.drawPolygon(new int[] {40, 80, 120}, new int[] {100, 20, 100}, 3);
提前致谢!!!
【问题讨论】:
-
fillPolygon将用您的颜色填充形状。 -
那么我需要编码什么?对不起,我是个菜鸟:(
-
g.drawPolygon绘制轮廓。g.fillPolygon该行中的颜色。如果您阅读documentation,您可以看到该方法。
标签: java polygon paintcomponent graphics2d