some changes
This commit is contained in:
49
DEV/DEV3.1/TP02/Part1/ImageManager.java
Normal file
49
DEV/DEV3.1/TP02/Part1/ImageManager.java
Normal file
@@ -0,0 +1,49 @@
|
||||
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];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user