1. Member
Join Date
May 2013
Posts
4
Rep Power
0

## Static fields

Hi guys!
My task is to develop the game. I've got an array of cells, where I should move my characters during the game.
Every Cell have got information (of integer type) about character containing there:
Java Code:
``` class Cell {
public int x,y;
public static int FirstX,FirstY;
public int WhoIsThere;```
Then in class GameLogic I have this code:
Java Code:
```class GameLogic{
static Cell[][] CellMassive=new Cell[7][7];
public static void FillItForTheFirstTime() {for (int countI=0; countI<7; countI++)
{for (int countJ=0; countJ<7;countJ++){
if (((countI==0)||(countI==1)||(countI==5)||(countI==6))&&
((countJ==0)||(countJ==1)||(countJ==5)||(countJ==6)))
{CellMassive[countI][countJ].WhoIsThere=3;}
else {CellMassive[2][2].WhoIsThere=1;CellMassive[2][4].WhoIsThere=1;
if (countI>2){CellMassive[countI][countJ].WhoIsThere=0;}}
}
}}
}```
And when I'm trying to run through this array to paint all of my cells...
Java Code:
```  public void paint(Graphics g){
GameLogic.FillItForTheFirstTime();
for (int countI=0; countI<7; countI++){
for (int countJ=0;countJ<7;countJ++){
g = getGraphics();
g.setColor(currColor);
if (GameLogic.CellMassive[countI][countJ].WhoIsThere==2){
g.fillRect(FirstX+countI*34, FirstY+countJ*34, Cell.Height, Cell.Height);}}
}
}```
...I can see only the beautiful green frame. I think, there is something wrong with "WhoIsThere" field, but I don't know, what :(

2. Member
Join Date
May 2013
Posts
4
Rep Power
0

## Re: Static fields

ok, don't mess, I've understood my mistakes :) Later I'll be more accurate with arrays and references

3. ## Re: Static fields

In case you didn't know, you should override paintComponent, not paint. And you're calling GameLogic.FillItForTheFirstTime() every time your component repaints.

BTW, you should look over the link in my sig. Capitalizing identifiers the way you did here can make your code confusing to experienced Java programmers.