DanTheMan
DanTheMan

Reputation: 11

Change variable but keep it saved?

I have a lot of things which I want to display in the GUI. So I put them all in an array. I run a for loop which adds them onto the screen one by one.

for(int num = 0; num<MYARRAY.length; num++){

        addToGui(MYARRAY[num], xCoords, yCoords);

    }

All the code works, but the coordinates are the same for everything I add, so everything overlaps on the screen. I tried

for(int num = 0; num<MYARRAY.length; num++){

        addToGui(MYARRAY[num], xCoords, yCoords);
        xCoords += 5;
    }

But everything on the screen just moves 5 pixels. So if xCoords = 5, I want to add something to the GUI with xCoords = 5, then add another thing to the screen with xCoords = 10 and so on. How would I do it?

Upvotes: 1

Views: 59

Answers (1)

Sid
Sid

Reputation: 4997

for(int num = 0; num<MYARRAY.length; num++){

        addToGui(MYARRAY[num], xCoords, yCoords);
        xCoords += 5;
    }

might this help? You are adding MYARRAY[0] everytime.

Upvotes: 2

Related Questions