I have a class Kostka , that has its own width (w), height (h), x and y positions for drawing it later on a 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 in ArrayList .. then call the maluj(g)
method for each of the Kostka object stored in the ArrayList
So far I've managed to make a method that stores the Kostka objects in ArrayList, but I dont 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);
}
}