I'm really stuck and don't know what to do
This code is a constructor, my problem is in the second line "Random color"Code:public Block (int x, int y) { pt = new Point(x, y) ; color=colors[new Random().nextInt(colors.length)]; }
it's supposed to select a random color for each block from an array containing 4 colors
here is how I call it:
my problem is, when I call it from the paint method (Applet) blocks[i][j].paint(g):Code:for (int i = 0 ; i < blocks.length ; i++) { for (int j = 0 ; j < blocks[i].length ; j++) { blocks[i][j] = new Block(i*20, j*20) ; } }
All blocks are the same color, I tried adding System...print to check if the problem is in the paint but it's not, all randoms are the same value.Code:public void paint (Graphics g) { g.setColor(this.color) ; g.fill3DRect(pt.x, pt.y, 15, 15, true) ; }
Any help would be great




Reply With Quote