TP04 from DEV3.1
This commit is contained in:
BIN
DEV/DEV3.1/TP04/.DS_Store
vendored
Normal file
BIN
DEV/DEV3.1/TP04/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
DEV/DEV3.1/TP04/Exercise1/.DS_Store
vendored
Normal file
BIN
DEV/DEV3.1/TP04/Exercise1/.DS_Store
vendored
Normal file
Binary file not shown.
17
DEV/DEV3.1/TP04/Exercise1/Makefile
Normal file
17
DEV/DEV3.1/TP04/Exercise1/Makefile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
run: compile
|
||||||
|
java -jar Project.jar
|
||||||
|
|
||||||
|
compile: build/Main.class
|
||||||
|
jar cvfe Project.jar fr/nathanbaudrier/Main -C build fr resources
|
||||||
|
|
||||||
|
build/Main.class: src/Main.java build/ImageWindow.class
|
||||||
|
javac -d build -cp build -sourcepath src $< -implicit:none
|
||||||
|
|
||||||
|
build/ClickSwapImageEvent.class build/ImageWindow.class: src/ClickSwapImageEvent.java src/ImageWindow.java build/ImageManager.class
|
||||||
|
javac -d build -cp build -sourcepath src src/ClickSwapImageEvent.java src/ImageWindow.java -implicit:none
|
||||||
|
|
||||||
|
build/ImageManager.class: src/ImageManager.java
|
||||||
|
javac -d build -cp build -sourcepath src $< -implicit:none
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BIN
DEV/DEV3.1/TP04/Exercise1/resources/dice.jpg
Normal file
BIN
DEV/DEV3.1/TP04/Exercise1/resources/dice.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
BIN
DEV/DEV3.1/TP04/Exercise1/resources/frog.png
Normal file
BIN
DEV/DEV3.1/TP04/Exercise1/resources/frog.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
DEV/DEV3.1/TP04/Exercise1/resources/random.jpg
Normal file
BIN
DEV/DEV3.1/TP04/Exercise1/resources/random.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
25
DEV/DEV3.1/TP04/Exercise1/src/ClickSwapImageEvent.java
Normal file
25
DEV/DEV3.1/TP04/Exercise1/src/ClickSwapImageEvent.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package fr.nathanbaudrier;
|
||||||
|
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class ClickSwapImageEvent extends MouseAdapter {
|
||||||
|
|
||||||
|
private ImageWindow window;
|
||||||
|
|
||||||
|
public ClickSwapImageEvent(ImageWindow window) {
|
||||||
|
this.window = window;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(MouseEvent event) {
|
||||||
|
System.out.println(this.window.manager.cursor);
|
||||||
|
if(event.getX() > this.window.getWidth() / 2) {
|
||||||
|
this.window.nextImage();
|
||||||
|
System.out.println(this.window.manager.cursor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.window.previousImage();
|
||||||
|
System.out.println(this.window.manager.cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
48
DEV/DEV3.1/TP04/Exercise1/src/ImageWindow.java
Normal file
48
DEV/DEV3.1/TP04/Exercise1/src/ImageWindow.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package fr.nathanbaudrier;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
public class ImageWindow extends JFrame {
|
||||||
|
|
||||||
|
public ImageManager manager;
|
||||||
|
private JLabel label;
|
||||||
|
|
||||||
|
public ImageWindow() {
|
||||||
|
this.manager = new ImageManager();
|
||||||
|
|
||||||
|
this.setSize(1024, 1024);
|
||||||
|
this.setLocationRelativeTo(null);
|
||||||
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
this.addMouseListener(new ClickSwapImageEvent(this));
|
||||||
|
|
||||||
|
this.nextImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nextImage() {
|
||||||
|
if(this.label != null) {
|
||||||
|
this.remove(this.label);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.label = new JLabel(this.manager.getNextImage());
|
||||||
|
this.label.setVerticalAlignment(JLabel.CENTER);
|
||||||
|
this.label.setHorizontalAlignment(JLabel.CENTER);
|
||||||
|
|
||||||
|
this.add(label);
|
||||||
|
this.revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void previousImage() {
|
||||||
|
if(this.label != null) {
|
||||||
|
this.remove(this.label);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.label = new JLabel(this.manager.getPreviousImage());
|
||||||
|
this.label.setVerticalAlignment(JLabel.CENTER);
|
||||||
|
this.label.setHorizontalAlignment(JLabel.CENTER);
|
||||||
|
|
||||||
|
this.add(label);
|
||||||
|
this.revalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
9
DEV/DEV3.1/TP04/Exercise1/src/Main.java
Normal file
9
DEV/DEV3.1/TP04/Exercise1/src/Main.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package fr.nathanbaudrier;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ImageWindow window = new ImageWindow();
|
||||||
|
window.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user