2015-04-23 97 views
-3

球员我想知道是否是一种方式来放置例如JLabels的列表,并用方法随机选择其中一个。从列表中随机选择一个对象(图像)

如果JLabels是图像,它仍然会工作?

感谢您的答案;)

+1

的[随机从列表中选择一个项目]可能重复(http://stackoverflow.com/questions/12487592/从列表中随机选择一个项目) –

+0

[从一组中挑选一个随机元素]的可能重复(http://stackoverflow.com/questions/124671/picking-a-random-element-from-一套) –

回答

0

是的,它是可能的:

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()));