title: How to stop the shape from disappearing when you click on new location?
body: <p>I have written this code that displays a shape on a mouse click, but I have problem. When I click on new location the shape disappear on the previous one. How can I stop that from happening?</p>
  
  <p>First Class:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.event.*;
  import java.awt.*;
  
  public class MouseClick {
      private static int x,y;
      private static DrawingObjects object = new DrawingObjects();
  
      public static void main(String[] args){
  
          JFrame frame = new JFrame("MouseClick");
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(400, 400);
          frame.add(object);
          object.addMouseListener(new AL());
      }
      static class AL extends MouseAdapter{
          public void mouseClicked (MouseEvent e){
              x = e.getX();
              y = e.getY();
              object.drawing(x, y);
          }
      }
  }
  </code></pre>
  
  <p>Second Class:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class DrawingObjects extends JPanel{
      private static int x,y;
  
      public void drawing(int xx, int yy){
          x = xx;
          y = yy;
          repaint();
      }
  
      public void paintComponent(Graphics g){
          super.paintComponent(g);
          g.fillRect(x, y, 20, 20);
      }
  }
  </code></pre>