#ArrayList of files

8 messages · Page 1 of 1 (latest)

pale star
#

Hello guys, Istead of using 3 different files i want to use one arraylist of type File and put the 3 files in it, how to convert this code snippet so that it uses arraylist? please help.

   File file1 = new File("src/application/png4.png");
    File file2 = new File("src/application/png12.png");
    File file3 = new File("src/application/Nightgif2.gif");
    
    if(is_day == 1 )
    {
        currWeathSymbol.setImage(new Image(file1.toURI().toString()));
        
    }
    else if(is_day == 0)
    {
        currWeathSymbol.setImage(new Image(file2.toURI().toString()));
        backgroundCond.setImage(new Image(file3.toURI().toString()));
    }
uncut coyoteBOT
#

This post has been reserved for your question.

Hey @pale star! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

pale star
#

Make an arrayList with file2 in 0, file1 in 1, and file3 doesnt have to be in it but it can be.

ArrayList<File> fileList = new ArrayList<>();
fileList.add(file2);
fileList.add(file1);
currWeathSymbol.setImage(new Image(fileList.get(is_day).toURI().toString()));
If(is_day == 0){backgroundCond.setImage(new Image(file3……….

As an example that could work

#

If you want it all to be 3 files just add it and use fileList.get(2) instead of file3

#

Btw file1,2,3 wont be added, you will add whatever file1 is worth.
Like
fileList.add(new File(“bla bla bla”));

#

Or google how to start with objects in an arraylist cause i forgor 💀