Hi
I have 2 points (X1,Y1)
and (X2,Y2)
how can I draw a line between them?
thanks
In Swing:
Graphics g;
g.drawLine(X1, Y1, X2, Y2);
IF you are drawing on a JPanel
, you will usually put this code in the paintComponent
method:
@Override
protected void paintComponent(Graphics g) {
g.drawLine(X1, Y1, X2, Y2);
}
To see all available methods on the Graphics
class, see the Javadocs.
Take a look at the Graphics.drawLine method.
You'll basically need to override some widget (like JPanel) or get a Canvas and in the paint method you do something like:
graphics.drawLine( p1.x, p1.y, p2.x, p2.y );
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