title: Adding shapes to JPanel on a button click
body: <p>I have a Class Circle with a button and a Class with a jPanel what i want to do is when that button is clicked a circle will be drawn on the panel and each time i click that button and change x and y "some how not implemented here" i got a circle on the JPanel over and over .
  How to do that, or is there a way to do what i descriped regardless of my code but i want the class circle to extends  Shape. </p>
  
  <pre><code>public class Window{
  
    private JFrame frame;
    private JPanel panel = new JPanel();
    Circle c = new Circle(frame, panel);
    // some other buttons 
    .
    .
   // some code to set the panel grid bag constaraints and background then
   frame.getContentPane().add(panel, gbc_panel);
  }
  </code></pre>
  
  <p>then the Circle Class</p>
  
  <pre><code>public class Circle extends Shape implements ActionListener{
  
    private JPanel Panel;
    private GridBagConstraints gbc_btnCircle;
    private JButton btnCircle;
  
    public void setPanel(JPanel panel) {
        Panel = panel;
    }
  
   public Circle(JFrame frame, JPanel panel){
      btnCircle = new JButton("Circle");
      // some code to set grid bag constraint then
      frame.getContentPane().add(btnCircle, gbc_btnCircle);
      setPanel(panel);        
      btnCircle.addActionListener(this);
  
   }
  
    public void paint(Graphics g) {
        super.paintComponents(g);
        g.setColor(Color.red);        
        g.fillOval(100, 100, 100, 100);     
        Panel.add(this);
    }
  
    public void actionPerformed(ActionEvent arg0) {
      repaint();      
    }
  }
  </code></pre>