|
I Have a question regarding arrays and filling a 4x4 grid..here is my function.
**this is the grid that is created....
////////////////////////////////////////////////////////////
//color grid
colorPanel= new JPanel();
colorPanel.setLayout(new GridLayout(4,8));
colorPanel.setPreferredSize(new Dimension (350,350));
colorPanel.setMaximumSize(new Dimension(350,350));
colorPanel.setBorder(new LineBorder(Color.black,2));
int idx=0;
for (int i =0; i<4; i++)
for (int j=0; j<4;j++)
colorPanel.add(gridCell[idx++],i,j);
//fillColorArray();
fillColorArray();
setGridColors();
mainPanel.add(colorPanel);
colorPanel.setBorder(BorderFactory.createTitledBor der("Color Grid"));
mainPanel.add(Box.createRigidArea(new Dimension(1000,0)));
//////////////////////////////////////////////////////////
*** this is the fill color array
private void fillColorArray(){
RED = (new Color(255,0,0));
YELLOW=(new Color(255,255,0));
ORANGE=(new Color(255,165,0));
GREEN=(new Color(0,100,0));
BLUE=(new Color(0,0,255));
PURPLE=(new Color(160,32,240));
BROWN=(new Color(165,42,42));
BLACK=(new Color(0,0,0));
PINK=(new Color(255,192,203));
GRAY=(new Color(190,190,190));
NAVY=(new Color(0,0,128));
SILVER=(new Color(139,134,130));
MAROON=(new Color(176,48,96));
WHITE=(new Color(255,255,255));
AQUA=(new Color(102,205,170));
FUCHISA=(new Color(238,130,238));
for(int i=0; i<16; i++) {
colorArray[i]=MAROON;
colorArray[i]=RED;
colorArray[i]=YELLOW;
colorArray[i]=GREEN;
colorArray[i]=BLUE;
....
...
..
}
}
* when i compile and run , the program just gives me one hudge color grid instead of a grid with 16 different colors..if anyone has any ideas what im doing wrong with this array I would really appreciate it. Thanks
|