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]; } }