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?
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With