How do you make an array of image icons and then call them, i have searched all over the internet for making an array of icons, but i have
found nothing. Below is my attempt at making an array of icons, but i cant seem to make it work. Basically, i want the image to match the value of the roll of the dice (rollVal)
Any help would be greatly appreciated, some code or link to tuturial, ect.
/** DiceRoller.java
*
* Roll, print, Gui
*
*/
import javax.swing.*;
public class DiceRoller extends JFrame
{
private ImageIcon[] image ;
public String[] images = { "empty", "dice1.jpg",
"dice2.jpg", "dice3.jpg", "dice4.jpg",
"dice5.jpg", "dice6.jpg" };
public Dice die;
private int rollVal;
public int rollNum;
private JLabel j1;
public DiceRoller(){
j1= new JLabel("");
die =new Dice();
int rollVal;
rollVal = die.roll();
image = new ImageIcon[images.length];
for(int i = 0; i < images.length; i++){
image[i] = new ImageIcon(images);
}
if (image!=null){
j1.setIcon(image[rollVal]);
}
System.out.println("Roll = "+die.roll());
}
}