Never use repaint()
in paint()
method, becouse repaint()
call paint()
. Try this code:
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
System.out.println(start);
if (start) {
g2.setColor(Color.BLACK);
g2.drawLine(winWidth / 2, winHeight / 2, winWidth / 2 + 5, winHeight / 2);
start = false;
} else {
g2.drawLine(100, 100, 200, 200);
}
// repaint();
}
You can see life cycle of start variable. I think you just need something like that:
public void paint(Graphics g) {
super.paintComponents(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.BLACK);
g2.drawLine(winWidth / 2, winHeight / 2, winWidth / 2 + 5, winHeight / 2);
}