It is not quite clear, what you want...
@Override public void
paint(Graphics g)
{
for(int col=0; i<*your colums*; ++i)
{
for(int row=0; i<*your rows*; ++i)
{
g.drawRect(cellWidth *col, cellHeight *row,
cellWidth, cellHeight);
}
}
}
To get the coordinate values:
cell y is cellWidth *column
, cell x is cellHeight *row
.
Another approach I can imagine is that every cell is an object
public class
Cell
{
public static final int
WIDTH= *your cell width*,
HEIGHT= *your cell height*;
public int
x, y;
public
Cell(int col, int row)
{
x= col* WIDTH;
y= row* HEIGHT;
}
public void
draw(Graphics g)
{
g.drawRect(x, y, WIDTH, HEIGHT);
}
}
usage:
initialize
int
COLUMNS= *your colums*,
ROWS= *your rows*;
Cell[]
cells=new Cell[COLUMNS][ROWS];
for(int col=0; i<COLUMNS; ++i)
{
for(int row=0; i<ROWS; ++i)
{
cells[col][row]=new Cell(col, row);
}
}
draw
@Override public void
paint(Graphics g)
{
for(Cell[] cell_col)
{
for(Cell cell : cell_col)
{
cell.draw(g);
}
}
}
To get the coordinate values:
cell x is cells[column][row].x
, cell y is cell x is cells[column][row].y