-3

guys I was wondering if it was a way to put a list of for example JLabels, and with a method select randomly one of them.

And if the JLabels are the images it will still work??

Thanks for all your answers;)

  • 1
    possible duplicate of [Randomly select an item from a list](http://stackoverflow.com/questions/12487592/randomly-select-an-item-from-a-list) – Harshal Patil Apr 23 '15 at 04:03
  • possible duplicate of [Picking a random element from a set](http://stackoverflow.com/questions/124671/picking-a-random-element-from-a-set) – JSON C11 Apr 23 '15 at 04:18

1 Answers1

0

Yes it's possible:

Random r = new Random();
        List<JLabel> yourList; //populate your list beforehand. yourList.add(JLabel blah); and so on
        JLabel randomJLabel = yourList.get(r.nextInt(yourList.size()));
Chamatake-san
  • 551
  • 3
  • 10