有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 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. # 2 楼答案

    两种最常见的方法:

    • 在一个循环中,将你的图标命名为1。巴布亚新几内亚,2。png等等,然后使用临时变量而不是名称进行迭代
    • 递归读取目录内容,将所有图像添加到ArrayList中,然后(如果需要)调用toArray()