I'm trying to make a simple game which i made array of 9 buttons and for loops to display them and add then to ContentPane.
I'm trying to add images to the buttons in the for loops and I cannot get it to work./ any help?
String[] images = {"rainbow.jpg", "leprechaun.jpg", "potofgold.jpg"}; // IMAGES
// --- ICONS ---
Icon Icon1 = new ImageIcon("rainbow.jpg");
Icon Icon2 = new ImageIcon("leprechaun.jpg");
Icon Iconwin = new ImageIcon("potofgold2.jpg");
Icon blank = new ImageIcon("blank.jpg");
//creates array of buttons called tiles
JButton[] tile = new JButton[9];
They are the arrays and Icons.
for(int i = 0; i < tile.length; i++)
{
contentPane.add(tile[i]);
tile[i].setIcon(images[1]);
tile[i].addActionListener(this);
}
I'm trying to make it random image to the buttons. selects randomly I cannot get it to work I get error on tile[i].setIcon(images[1])
even when trying to just place it the 2nd image it give sme error
method setIcon in class AbstractButton cannot be applied to given types;
tile[i].setIcon(images[1]);