You could make each of your images into an array of name objects? Like this:
Names[] name = new Names[fruit.length]; //add this under your fruit array initialization
Then you could do this in setup:
for(int i = 0; i<fruit.length; i++)
{
name[i] = new Names(fruit[i]); //set each index of the Names object to the corresponding index in your fruit array
}
Also, where you declare index, initialize it to some value, like this:
int index = 0;
And then in your display() function?
Have something to do with the random index, like this:
void display(){
stroke(0);
imageMode(CENTER);
img = name[index]; //set the random index here!
img.resize(200,200);
image(img,width/2,height/2);
}
And everything should work as you intended. The main problem you were having, was that even after changing the index, your display function inside your Names object didn’t know about the change, which is why nothing happened. Hopefully this helps!
EnhancedLoop7