Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is a "2-dimensional arrayList" practical, and problem creating one?

843785Dec 20 2008 — edited Dec 21 2008
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 18 2009
Added on Dec 20 2008
12 comments
313 views