I have a Kostka class that has its own values ββfor width (w), height (h), x and y for drawing it later using JPanel using this method.
void maluj(Graphics g) { g.drawRect(x, y, w, h); }
Now I need to make more of them and add them to ArrayList .. then call the maluj(g) method for each of the Kostka objects stored in ArrayList
So far I have managed to create a method that stores Kostka objects in an ArrayList , but I donβt know how to call their methods
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); } }
source share