Drawing Lines
From Progzoo
Drawing Lines
g.drawLine(60,20,60,100) draws a line from (60,20) to (60,100)
of the Graphic g. The current color and stroke will be used.
We can control the thickness of the line and the end-cap.
The cap determines what happens at the end of a line.
With the Graphics and the Graphics2D classes we can specify features of the Stroke used to draw the line.
- BasicStroke
- Sets the thickness of the line to be drawn.
- g.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER))
- The three parameters are thickness, cap style and join style.
- The cap style dictates what happens at the end of the line.
BasicStroke.CAP_BUTTBasicStroke.CAP_ROUNDBasicStroke.CAP_SQUARE
- The join style determines what happens where two line of a polygon meet.
-
BasicStroke.JOIN_MITERBasicStroke.JOIN_ROUNDBasicStroke.JOIN_BEVEL
