TP04 from DEV3.1
This commit is contained in:
39
DEV/DEV3.1/TP04/Exercise1/src/ImageManager.java
Normal file
39
DEV/DEV3.1/TP04/Exercise1/src/ImageManager.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package fr.nathanbaudrier;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class ImageManager {
|
||||
|
||||
private ImageIcon[] images;
|
||||
public int cursor;
|
||||
|
||||
public ImageManager() {
|
||||
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
this.images = new ImageIcon[3];
|
||||
this.images[0] = new ImageIcon(loader.getResource("resources/dice.jpg"));
|
||||
this.images[1] = new ImageIcon(loader.getResource("resources/frog.png"));
|
||||
this.images[2] = new ImageIcon(loader.getResource("resources/random.jpg"));
|
||||
}
|
||||
|
||||
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