I'm trying to create a bunch of the same objects (Grass) with a loop in different spaces. I have a grid and I want it to fill up the entire grid with different colors. So I have this code so far:
public stage() {
super(null);
cast = new Cast();
cast.setBounds(10, 10, cast.getWidth(), cast.getHeight());
this.add(grid);
for (int i = 0; i <= 19; i++) {
obj = new Object[] {
new Grass (cast.cells[i][i])
};
}
}
This obviously doesn't work and only makes a colored cell in the last spot of the grid. Is there anyway to make a loop for objects in every spot?
objto anewarray each time through the loop... What are you expecting to happen? Can you use an ArrayList?