title: Java - calling methods of an object that is in ArrayList
body: <p>I have a class  <strong>Kostka</strong> , that has its own width (w), height (h), x and y positions for drawing it later on a JPanel using this method   </p>
  
  <pre><code>void maluj(Graphics g) {
      g.drawRect(x, y, w, h);
  }
  </code></pre>
  
  <p>Now I need to make more of them and add them in ArrayList .. then call the <code>maluj(g)</code> method for each of the <strong>Kostka</strong> object stored in the ArrayList  </p>
  
  <hr>
  
  <p>So far I've managed to make a method that stores the Kostka objects in ArrayList, <strong>but I dont know how to call their methods</strong>  </p>
  
  <pre><code>class MyPanel extends JPanel {
      ArrayList kos = new ArrayList(5);
  
      void addKostka() {
          kos.add(new Kostka(20,20,20,20));
      }
  
      public void paintComponent (Graphics g) {
          super.paintComponent(g);
      }
  }
  </code></pre>