title: Painting mutliple objects in 1 JFrame
body: <p>I'm trying to make my program object oriented and I'm attempting to split it into several classes. The short version is that I want to paint  different objects in 1 <code>JFrame</code>. So I created a class per object that I wanted to paint, defined the object in my method and then add them to my frame. The problem is that only the last component is painted in the frame. I tried adding the objects to a <code>JPanel</code> first but that doesn't seem to work.</p>
  
  <h2><code>trees1</code></h2>
  
  <pre><code>public class trees1 extends JComponent{
  
  public final ImageIcon  pokemontree;
  
  public trees1(){
      ImageIcon poke = new ImageIcon("pokemontree.png");
  
      Image image = poke.getImage(); // transform it 
      pokemontree = new ImageIcon(newimg);  // transform it back
  }
  
  public void paintComponent (Graphics g){
      Graphics2D g2 = (Graphics2D) g;
      pokemontree.paintIcon(this,g2 , 100,200);
  }
  }
  </code></pre>
  
  <h2><code>testing</code></h2>
  
  <pre><code>// main program
  public class testing {
  
  public static void main(String[] args){
      JFrame win = new JFrame();
      win.setSize(600,400);
      win.setTitle("Test");
      win.setResizable(false);
      win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
  
      trees1 exo = new trees1();
      Playerwalking p1 = new Playerwalking(1,2);
      win.add(exo);
      win.add(p1);
  
      win.setVisible(true);
  }
  </code></pre>