如何绘制三角形? [英] How do I draw a triangle?
本文介绍了如何绘制三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何绘制一个矩形和一个圆形并用g.drawRect
或g.drawOval
进行绘制.但是没有g.drawtriangle
.有没有办法画出一个三角形,而我不必将其画在三角形的每一侧?
I know how to draw a rectangle and circles and ect with g.drawRect
or g.drawOval
. But there is no g.drawtriangle
. Is there a way to draw a triangle with out me having to draw it out each side of the triangle?
推荐答案
您可以使用Graphics.drawPolygon(int[], int[], int)
,其中第一个int []是x值的集合,第二个int []是y值的集合, int是数组的长度. (在三角形的情况下,整数将为3)
You may use Graphics.drawPolygon(int[], int[], int)
where the first int[] is the set of x values, the second int[] is the set of y values, and the int is the length of the array. (In a triangle's case, the int is going to be 3)
示例:
graphics.drawPolygon(new int[] {10, 20, 30}, new int[] {100, 20, 100}, 3);
输出:
这篇关于如何绘制三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文