开发者

image icon, list and random in java

I have 4 pictures:

ImageIcon f1 = new ImageIcon("C:\\Users\\Student\\Desktop\\pic1.jpg");
ImageIco开发者_Go百科n 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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜