0

I'm reading a couple images with the exact same name but numbered from 1-6 so I've used and array to read in the images, for example AstroWalkLeft1, AstroWalkLeft2 into arimgAstroWalkleft[]. This is what I have:

public void GetImages() {
    imgMonster = new ImageIcon("Assets\\MonsterSingle.png").getImage();
    for (int i = 1; i <= nASTROIMGMAX; i++) {
        arimgAstroWalkLeft[i] = new ImageIcon("Assets\\AstroWalkLeft" + i + ".png").getImage();
        arimgAstroWalkRight[i] = new ImageIcon("Assets\\AstroWalkRight" + i + ".png").getImage();
    }
    imgAstroStandLeft = new ImageIcon("Assets\\AstroStandLeft.png").getImage();
    imgAstroStandRight = new ImageIcon("Assets\\AstroStandRight.png").getImage();
    imgBackground1 = new ImageIcon("Assets\\Hallway.png").getImage();
    imgBackground2 = new ImageIcon("Assets\\Observation Room.png").getImage();
}

My problem is replacing the numbers in the image's name to the variable in my loop. I'm wonder how I put that variable in where the number once was.

BlueBarren
  • 321
  • 7
  • 24
  • Could you give some example of what you want to achieve? – Dominic Jan 10 '14 at 13:44
  • I think you'll have to rephrase your question a bit: what exactly would you like this code to do that it is not doing now? – herman Jan 10 '14 at 13:44
  • Also, arrays are 0-based. And it'd better using a List... – Andrea Ligios Jan 10 '14 at 13:46
  • Well my problem is that NetBeans doesn't like "AstroWalkLeft" + i + ".png" and so it won't read in my images. – BlueBarren Jan 10 '14 at 13:51
  • 1) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve). 2) One way to get image(s) for an example is to hot-link to the images seen in [this answer](http://stackoverflow.com/a/19209651/418556). – Andrew Thompson Jan 10 '14 at 18:11

0 Answers0