How do I draw more than one line with the drawline? It always deletes the previous one when drawing a new one, but I want to keep it. The code is as follows
public class DrawLines extends JPanel{
private final int[] origemXY = new int[2];
private final int[] destinoXY = new int[2];
Graphics2D g2;
@Override
public void paintComponent(Graphics g){
super.paintComponents(g);
drawLinha(g);
}
public void drawLinha(Graphics g){
g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(2));
g2.setColor(Color.red);
g2.drawLine(origemXY[0], origemXY[1], destinoXY[0], destinoXY[1]);
}
public void drawLinha(int origemXY[], int destinoXY[]){
this.origemXY[0] = origemXY[0];
this.origemXY[1] = origemXY[1];
this.destinoXY[0] = destinoXY[0];
this.destinoXY[1] = destinoXY[1];
repaint();
}
}
From my other class I send the coordinates to the vectors and the line is drawn, but if you send other coordinates to draw another line, the previous line is deleted. I think the repaint does this by deleting what it has and drawing again, but if you take it out nothing is drawn. I need to draw more than one, thank you.