Hi,
How can I fill color on the grid boxes randomly?
Rather than orderly as shown in picture here:
public class grid extends JPanel{
Label one = new Label();
Label two = new Label();
Label three = new Label();
Label four = new Label();
public static void main(String[] args){
JFrame jf=new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(new YAnswers());
jf.pack();
jf.setVisible(true);
}
grid (){
int rows=10; int cols=10;
setLayout(new GridLayout(rows,cols));
add(one); one.setBackground(Color.red);
add(two); two.setBackground(Color.orange);
add(three); three.setBackground(Color.green);
add(four); four.setBackground(Color.black);
boxes[] bx=new boxes[rows*cols];
for(int i=0;i<rows*cols;i++){
System.out.println("i"+i);
bx[i]=new boxes();
if(i%2<1)
bx[i].setColor(1);
add(bx[i]);
}
} //end grid()
}