[java] How to draw lines in Java

I understand you are using Java AWT API for drawing. The paint method is invoked when the control needs repainting. And I'm pretty sure it provides in the Graphics argument what rectangle is the one who needs repainting (to avoid redrawing all).

So if you are presenting a fixed image you just draw whatever you need in that method.

If you are animating I assume you can invalidate some region and the paint method will be invoked automagically. So you can modify state, call invalidate, and it will be called again.