java在数组中声明52个图像图标的最简单方法是什么 1 年,8 月 Questions & Answers 4167 我有一个imageicon数组,声明它们比声明每个单独的图像更简单。 ImageArray[0]=新的ImageIcon(“resources/images/cards/6.png”)
# 1 楼答案 假设图像为0。巴布亚新几内亚至51。参考资料中的png。图像/卡片文件夹: ImageIcon[] images = new ImageIcon[52] for(int i=0;i<52;i++){ images[i] = new ImageIcon("resources/images/cards/"+i+".png"); }
# 2 楼答案 两种最常见的方法: 在一个循环中,将你的图标命名为1。巴布亚新几内亚,2。png等等,然后使用临时变量而不是名称进行迭代 递归读取目录内容,将所有图像添加到ArrayList中,然后(如果需要)调用toArray()
# 1 楼答案
假设图像为0。巴布亚新几内亚至51。参考资料中的png。图像/卡片文件夹:
# 2 楼答案
两种最常见的方法:
ArrayList
中,然后(如果需要)调用toArray()