grid container

12 x 12 grid

Page 1 of 1

1 Replies - 2066 Views - Last Post: 15 December 2008 - 07:50 PM Rate Topic: -----

#1 jimmy911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-December 08

grid container

Post icon  Posted 15 December 2008 - 07:32 PM

How can I make a 12 X 12 grid where I can have multiple inhabitants in a square.
Do I put a container in the cell?
What would the code look like for this 12 x 12 grid
I have know idea what to do


I have this code already for a board game,but do not know what to do next

public class Board {
private static final int Row = 12;
private static final int Column = 12;
private static final int RowHeight = 50;
private static final int ColumnWidth = 50;
int grid [][] = new int [Row][Column];
//...
}

Is This A Good Question/Topic? 0
  • +

Replies To: grid container

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4424
  • View blog
  • Posts: 12,293
  • Joined: 18-April 07

Re: grid container

Posted 15 December 2008 - 07:50 PM

I guess it depends on what you mean by inhabitants. If you are talking about a grid style layout manager for a GUI where each section might have multiple buttons or controls, then you would actually make a 2D array of JPanels.

If you are talking about objects, you would create a class, define its various parts, then create a 2D array of that object.

So lets say I have a square for use in a chess game. I would first define a square class that would have things like width, height, color and maybe if it has a piece on it right now. Then I would create a 2D array of square objects...

// Create a 2D Board of 64 square objects.
square board[][] = new square[8][8];



This will now allow each slot of the board to have an object which can contain various data members like variables, functions, inner classes etc.

Hopefully this is what you were referring to. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1