public class ShowImage extends JFrame{
private static final int IMAGE_NUMBER=6;
private Image[] image = new Image[IMAGE_NUMBER];
public ShowImage(){
for(int i=1;i<=IMAGE_NUMBER;i++){
try{
//File file = new File("pictures//"+String.valueOf(i)+".jpg");
// image[i-1]=ImageIO.read(file);
image[i-1] = Toolkit.getDefaultToolkit().createImage("pictures//"+i+".jpg");
}
catch(Exception ex){
ex.printStackTrace();
}
}
Random random = new Random();
ImageIcon oneIcon = new ImageIcon(image[random.nextInt(IMAGE_NUMBER)]);
this.add(new JLabel(oneIcon));