Re: Need Help with Arrays
Quote:
How do i insert different images into a array of buttons i have created.
You can not insert images into an array of buttons.
You can set the image for each button in the array.
For example:
JButton[] someBtns = ... // define an array of buttons
...
someBtns[ix].<THE METHOD TO SET THE IMAGE>(theImage); // set image for a button in the array
Re: Need Help with Arrays
Thanks Norm!
I just want to double check, if my coding is correct.
centerPnl = new JPanel(new GridLayout(3, 3, 5, 5));
picBtn = new JButton[9];
for (int i = 0; i < picBtn.length; i++) {
picBtn[i] = new JButton("");
centerPnl.add(picBtn[i]);
}
picBtn[0].setIcon(new ImageIcon("pic01.jpg"));
picBtn[1].setIcon(new ImageIcon("pic02.jpg"));
picBtn[2].setIcon(new ImageIcon("pic03.jpg"));
picBtn[3].setIcon(new ImageIcon("pic04.jpg"));
picBtn[4].setIcon(new ImageIcon("pic05.jpg"));
picBtn[5].setIcon(new ImageIcon("pic06.jpg"));
picBtn[6].setIcon(new ImageIcon("pic07.jpg"));
picBtn[7].setIcon(new ImageIcon("pic08.jpg"));
picBtn[8].setIcon(new ImageIcon("pic09.jpg"));
Thanks for you help!
Re: Need Help with Arrays
Quote:
I just want to double check, if my coding is correct.
What did the compiler say?