I have two classes. block and main
public Block(Stage stage) {
super(stage);
//fill array
where[t][s]=i;
i++;
system.out.println(where[t][s]);

}
and the main.
the problem is I create an instance of the class block and I know it runs because I put a system.out there and the I a list of printed numbers in a dos window.
the problem is in the main class I call it like
system.out.println(Block.where[0][2]);
and the output is "0";
????
why is this?
AND HOW to solve?
thanks for looking

Hi everyone,

What is this Stage class about??

Richard West

Try using "getters" and "setteres":

public class Block
{
       private int[][] where;
       
       public Block(Stage s)
       {
              super(s);
              fillArray(4,4);
       }
 
       public void fillArray(int firstIndex, int secondIndex)
       {
                  where = new int[firstIndex][secondIndex];
                  int x = 0; 
                  for (int i=0; i<firstIndex; i++)
                  {
                          for (int j=0; j<secondIndex; j++)
                          {
                                  where[i][j] = x;
                                  x++;
                          }
                 }
       } 

      [B] public int getElement(int firstIndex, int secondIndex)
       {
               return where[firstIndex][secondIndex];
       }[/B]
}


------Main Class-----------

public class Test
{
        public static void main(String[] args)
        {
                 Block b = new Block(StageName);
                 System.out.println(b.getElement(0,2));
        }
}

By the way, I don't understand the Stage part either. Unless you are extending a class that takes a Stage as an argument, you don't need that...It does look pretty useless though.

the stage class is needed, it was simpler just to tell you as little as possible.
that getters and setters is what I was looking for.
I need a little change to it which I cant solve.
instead of one object which fills the array
I need lots of objects and them to keep filling the next array block.
I try'd

public Block(Stage stage) {
   super(stage);
           if (s==4){s=0; t++;}
           c=c+10; 
           s++;
           fillArray(t,s,c);
}
public void fillArray(int t, int s, int c)
   {
    System.out.println(s);
    System.out.println(c);
         where[t][s]=c;
         System.out.println(where[t][s]);
    } 

but the system.out's always say "0"
I think its becuase every time I create a new object it calls the default construct so t,s,c will equal 0 again?
how to fix?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.