Multiple text files
in
Programming Questions
•
2 years ago
Right now I'm having trouble getting my program to read the multiple text files I have in my data folder. My counter is working for the images, but not the text files. This is what I have so far, and when my mouse hovers over the first picture, the name is displayed below, but when the mouse hovers over the other pictures, I get an error saying "ArrayIndexOutOfBoundsException: 1". The names of my pictures and the corresponding text files are the same names (0.jpg, 0.txt)
PImage[] images = new PImage[8];
String[] names = new String[8];
void setup() {
size(900, 700);
for (int i=0; i <images.length; i++) {
images[i] = loadImage(i + ".jpg");
}
for (int i=0; i < names.length; i++) {
names = loadStrings(i + ".txt");
}
}
void draw() {
background(0);
float w = float(width) / images.length;
for (int i=0; i < images.length; i++) {
float x = i*w;
float y = 0;
imageMode(CORNER);
image( images[i], x, y, w, w);
// check for rollover
if (mouseX > x && mouseX <= x+w && mouseY > y && mouseY <=y+w) {
noFill();
stroke(255);
rect(x, y, w-1, w);
imageMode(CENTER);
image(images[i], width/2, 400);
text(names[i], x+40, y+150);
}
}
}
PImage[] images = new PImage[8];
String[] names = new String[8];
void setup() {
size(900, 700);
for (int i=0; i <images.length; i++) {
images[i] = loadImage(i + ".jpg");
}
for (int i=0; i < names.length; i++) {
names = loadStrings(i + ".txt");
}
}
void draw() {
background(0);
float w = float(width) / images.length;
for (int i=0; i < images.length; i++) {
float x = i*w;
float y = 0;
imageMode(CORNER);
image( images[i], x, y, w, w);
// check for rollover
if (mouseX > x && mouseX <= x+w && mouseY > y && mouseY <=y+w) {
noFill();
stroke(255);
rect(x, y, w-1, w);
imageMode(CENTER);
image(images[i], width/2, 400);
text(names[i], x+40, y+150);
}
}
}
1