Files
BUT2/DEV/DEV3.1/TP02/Part1/ImageManager.java
2025-10-02 10:48:05 +02:00

50 lines
1.2 KiB
Java

import java.io.File;
import javax.swing.ImageIcon;
public class ImageManager {
private ImageIcon[] images;
public int cursor;
public ImageManager() {
File resourcesDirectory = new File("../resources/");
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
File[] files = resourcesDirectory.listFiles();
if(files != null) {
this.images = new ImageIcon[files.length];
this.cursor = 0;
for(File file : files) {
this.images[this.cursor] = new ImageIcon(file.getPath());
this.cursor++;
}
this.cursor = 0;
}
}
}
public ImageIcon getNextImage() {
if(this.cursor >= this.images.length - 1) {
this.cursor = 0;
} else {
this.cursor++;
}
return this.images[this.cursor];
}
public ImageIcon getPreviousImage() {
if(this.cursor <= 0) {
this.cursor = this.images.length - 1;
} else {
this.cursor--;
}
return this.images[this.cursor];
}
}