Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw a triangle?

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?

like image 544
jack zhang Avatar asked Nov 28 '22 01:11

jack zhang


1 Answers

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)

Example:

graphics.drawPolygon(new int[] {10, 20, 30}, new int[] {100, 20, 100}, 3);

Output:

Output

like image 155
Constant Avatar answered Dec 05 '22 18:12

Constant