To draw a triangle, we are using Line2D class of package java.awt.geom.*. This class provides a line segment in (x, y) coordinate space. We have draw three line segments using the class Line2D to create a triangle.
Draw a Triangle using a Line2D
This section illustrates you how to draw a triangle using a Line2D.
To draw a triangle, we are using Line2D class of package java.awt.geom.*. This class provides a line segment in (x, y) coordinate space. We have draw three line segments using the class Line2D to create a triangle.
The setPaint() method paints the line segment.
Here is the code of DrawTriangleUsingLine.java
import java.awt.*;
|
Output will be displayed as: