I have used the paintComponent
method to draw shapes on my panel. However, every time I minimize the frame or resize it, they disappear. Not sure what to add to my code.
public class ShapePanel extends JPanel implements ActionListener, MouseListener{
int a,b,c,d;
Graphics2D g2D;
private Rectangle2D rect = new Rectangle2D(a,b,c-a,d-b);
public ShapePanel(){
addMouseListener(this);
setLayout(new GridLayout());
}
public void paintComponent(Graphics g) {
g2D = (Graphics2D) g;
g2D.draw(rect);
repaint();
}
//get methods for coordinates: MousePressed, MouseReleased