Java多个图像与循环



我想创建一个以上的循环图像。然而,它似乎不是这样工作的。问题是图像不能有数字作为名称。有没有办法做到这一点?

for(int i = 0; i < getObjects().size(); i++) {
Image i = new Image(getObjects().get(i).getImagePath()));
}

尝试制作一个 Image 类型的 ArrayList,您可以将所有图像存储在那里

ArrayList<Image> imageArrayList = new ArrayList<Image>();
for(int i = 0; i < getObjects().size(); i++) {
imageArrayList.add(new Image(getObjects().get(i).getImagePath());
}

如果你刚开始使用java,不希望在返回代码时如此混乱,可以使用这样的东西

ArrayList<Image> imageArrayList = new ArrayList<>();//Creates the list that will store images
for(int i = 0; i < getObjects().size(); i++) {
Image image = new Image(getObjects().get(i).getImagePath());//Create the image you want to store
imageArrayList.add(image);//Add that image to the arraylist
}

最新更新