user721588
user721588

Reputation:

image icon, list and random in java

I have 4 pictures:

ImageIcon f1 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic1.jpg");
ImageIcon f2 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic2.jpg");
ImageIcon f3 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic3.jpg");
ImageIcon f4 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic4.jpg");
Random r = new Random();

How can I put them into the list (or another data structure?) and randomly pick them one by one? I mean I pick for example f2, delete f2 in the list, them pick f4, delete f4 in the list... until all the elements are picked.

Thanks!

Upvotes: 2

Views: 533

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500815

Just put them into a list and call Collections.shuffle - then iterate over the list, which will be in a random order.

Upvotes: 6

Related Questions