I want to create an arraylist of arraylists of jlabels to handle a grid for a simple BMTron game. Is there a better alternative? I'm fairly new to the arrayList class. Here is how I'm trying to do it and I know that there is something very wrong in my logic when I try to add the jlabels and my inner for loop, but am unsure of what it may be. Should be somthing like the generic array right? array[row].length? How to do this in arraylist?
ArrayList<ArrayList> rowList = new ArrayList(30);//used to create 2dimensional list
ArrayList<JLabel> playGridList = new ArrayList(30);//set to 30 for clearity
//Handle Rows
for(int row = 0; row<rowList.size(); row++)
{
rowList.add(new ArrayList(30));
//Handle Columns
//rowList.size(row, col); THIS LINE IS OF COURSE THE PROBLEM
//WHAT SHOULD IT BE?
for(int col = 0; col<rowList.size(row, col); col++)
{
playGridList.add(new JLabel("empty"));
gridPlayPanel.add(rowList.get(row, col));
}
}
Edited by: watwatacrazy on Dec 20, 2008 12:27 PM