title: Adding multiple graphic objects to one JFrame
body: <p>Here is my code it is a guy and a background but only one thing shows up at a time or sometimes nothing at all.
  I have a brain class, a frame class, a redPlayer class, and a background class.
  The way it works is the brain makes a player and a brain and adds it to the frame.</p>
  
  <p>I think it has something to do with layouts but I tried everything but nothing works.
  Please Help!!!</p>
  
  <p>Thanks in advance.</p>
  
  <p>here is the brain:</p>
  
  <pre><code> public class Brain 
   {
     private Frame frame;
     private static RedPlayer redPlayer;
     private Background background;
     private SensorKeys sensor;
  
  public Brain()
  {
      frame = new Frame();
      redPlayer = new RedPlayer();
      background = new Background();
      sensor = new SensorKeys();
  
      frame.addComponent(redPlayer);
      frame.addComponent(background);
      frame.addKeySensor(sensor);
  
      redPlayer.revalidate();
  }
  
  public static void setRedPlayerVelX(double vx)
  {
      redPlayer.setVelX(vx);
  }
  
  public static void setRedPlayerVelY(double vy)
  {
      redPlayer.setVelY(vy);
  }
  
  public static void makeRedPlayerBullet()
  {
  
  }
  </code></pre>
  
  <p>}
  `</p>
  
  <p>here is the frame class</p>
  
  <pre><code>public class Frame
  {
  private JFrame jf;
  
  public Frame()
  {
      drawFrame();
  }
  
  public void drawFrame()
  {
      jf = new JFrame();
      jf.setSize(800, 600);
      jf.setLocation(10, 10);
      jf.setVisible(true);
      jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      jf.setBackground(Color.WHITE);
      jf.setLayout(null);
  }
  
  public void addComponent(JComponent jc)
  {
      jc.setBounds(jc.getX(), jc.getY(), 100, 100);
      jf.add(jc);
  }
  
  public void addPanel(JPanel jp)
  {
      jf.add(jp);
  }
  
  public void addKeySensor(KeyListener kl)
  {
      jf.addKeyListener(kl);
  }
  
   }
  </code></pre>
  
  <p>here is the player class:</p>
  
  <pre><code>public class RedPlayer extends JComponent implements ActionListener
  {
  private int x,y;
  private double velX = 0, velY = 0;
  private Timer timer = new Timer(2,this);
  private Image redplayer;
  
  public RedPlayer()
  {
      x = 100;
      y = 100;
  
      ImageIcon II = new ImageIcon("redPlayerRight.png");
      redplayer = II.getImage();
  
      revalidate();
      timer.start();
  }
  
  public void paintComponent(Graphics g)
  {
      super.paintComponent(g);
      Graphics2D graphics = (Graphics2D) g;
  
      graphics.drawImage(redplayer, x,y, null);
  }
  
  
  public void actionPerformed(ActionEvent arg0) 
  {   
      x += velX;
      y += velY;
  
      repaint();
      revalidate();
  }
  
  
  public void setVelX(double vx)
  {
      velX = vx;
  }
  
  public void setVelY(double vy)
  {
      velY = vy;
  }   
  }
  </code></pre>
  
  <p>And Lastly here is the background class:</p>
  
  <pre><code>public class Background extends JComponent
  {
  public void paintComponent(Graphics g)
  {
      super.paintComponent(g);
      Graphics2D graphics = (Graphics2D) g;
  
      graphics.setColor(Color.green);
      graphics.fillRect(0, 400, 500, 200);
  }
   }
  </code></pre>