I made a program that creates a line from two points in random positions in a JFrame. But I realized that when I minimized the window and re-maximized it, I would get a new line generated by two different points from the previous ones. What is going wrong?
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.red);
int random1 = (int) (800 * Math.random());
int random2 = (int) (800 * Math.random());
int random3 = (int) (800 * Math.random());
int random4 = (int) (800 * Math.random());
g.drawLine(random1, random2, random3, random4);
System.out.println("Random 1: " + random1);
System.out.println("Random 2: " + random2);
System.out.println("Random 3: " + random3);
System.out.println("Random 4: " + random4);
}