Search code examples
javalinedrawgraphics2dstroke

How does drawLine Work?


In order to solve a scaling problem, I have the following question:
graphics.drawLine(x1,y1,x2,y2); draws a line between 2 points.
Does it draw this Lines "on Top" of those points or is it drawn below them?
See my Image for clarification:
Example The upper example shows how an Oval is drawn with graphics.fillOval(x,y,w,h); where the black point is the x and y coordinate and the red circle is the actual oval...
Is it the same using graphics.drawLine() when using a new BasicStroke(3.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND) like in the lower example?
Or is the line actually drawn centered to the coordinates? Any help is appreciated.


Solution

  • For drawLine(), the beginning of the arc portion will be at x location, so your picture is wrong. The rounded cap will protrude to the left of the left dot, and to the right of the right dot.