title: I'm trying to place multiple paintComponents in a JFrame.
body: <p>Pressing Button 1 puts a box in pane2, pressing Button 2 puts another box up, but the 1st one disappears.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  
  public class GuiDemo extends JPanel implements ActionListener {
      JFrame pane1 = new JFrame("pane1");
      JFrame pane2 = new JFrame("pane2");
      public  GuiDemo(){
  
          pane1.setSize(400,400);
          pane1.setLocation(100, 100);
          pane2.setSize(400,400);
          pane2.setLocation(800, 100);
          pane1.setVisible(true);
          pane2.setVisible(true);
          pane1.setLayout(new FlowLayout());
          JButton b1 = new JButton("Button 1");
          JButton b2 = new JButton("Button 2");
          pane1.add(b1);
          pane1.add(b2);
          b1.setVisible(true);
          b1.addActionListener(this);
          b2.setVisible(true);
          b2.addActionListener(this);
      }
  
      public void actionPerformed(ActionEvent e){
          switch (e.getActionCommand()){
              case "Button 1":{
                  placeCircle pc = new placeCircle(0);
                  pane2.add(pc);
                  pane2.setVisible(true);
                  break;}
              case "Button 2":{
                  placeCircle pc = new placeCircle(1);
                  pane2.add(pc);
                  pane2.setVisible(true);
                  break;}
          }
      }
  
      public static void main(String[] args) {
           new GuiDemo();
      }
  
  }
  </code></pre>
  
  <p>a is passed as the offset beteween box 1 and box 2.</p>
  
  <pre><code>class placeCircle extends JPanel{
      int a;
      public placeCircle(int a){
          this.a = a;
  
      }
      public void paintComponent(Graphics g){
          super.paintComponent(g);
          g.setColor(Color.BLACK);
          g.drawRect(20+a*100, 20, 20, 20);       
      }
  
  }
  </code></pre>
  
  <p>but my main question is, should I be using painComponent?</p>