Compare commits
2 Commits
ef6ca77dc6
...
3108dea35f
| Author | SHA1 | Date | |
|---|---|---|---|
| 3108dea35f | |||
| cd5f593c57 |
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
DEV/DEV3.2/TP01/Exercise1/GenericList.java
Normal file
33
DEV/DEV3.2/TP01/Exercise1/GenericList.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
class GenericList {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ArrayList<Integer> integerList = new ArrayList<>(); // Peut recevoir des Integer
|
||||||
|
integerList.add(1);
|
||||||
|
integerList.add(2);
|
||||||
|
integerList.add(3);
|
||||||
|
|
||||||
|
ArrayList<Float> floatList = new ArrayList<>(); // Peut recevoir des Float
|
||||||
|
floatList.add(1.1f);
|
||||||
|
floatList.add(1.2f);
|
||||||
|
floatList.add(1.3f);
|
||||||
|
|
||||||
|
long longNumber = 1000000000L;
|
||||||
|
float floatNumber = 5.3f;
|
||||||
|
int integerNumber = 10;
|
||||||
|
ArrayList<Number> numberList = new ArrayList<>(); // Peut recevoir des Float, Integer et Long
|
||||||
|
numberList.add(longNumber);
|
||||||
|
numberList.add(floatNumber);
|
||||||
|
numberList.add(integerNumber);
|
||||||
|
|
||||||
|
System.out.println(integerList.toString());
|
||||||
|
System.out.println(floatList.toString());
|
||||||
|
System.out.println(numberList.toString());
|
||||||
|
|
||||||
|
// La méthode addAll() copie le contenu d'une collection dans la collection courante.
|
||||||
|
// Le type de la collection doit être de type E ou extends E.
|
||||||
|
// Ici, les class Float, Integer et Long extends de Number, donc on peut faire les opérations suivantes :
|
||||||
|
// - numberList.addAll(integerList);
|
||||||
|
// - numberList.addAll(floatList);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
DEV/DEV3.2/TP01/Exercise2/ArrayMethods.java
Normal file
10
DEV/DEV3.2/TP01/Exercise2/ArrayMethods.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ArrayMethods {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(args.toString()); // a)
|
||||||
|
System.out.println(Arrays.copyOf(args, 5)); // b)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
27
DEV/DEV3.2/TP02/Exercise1/Recursion.java
Normal file
27
DEV/DEV3.2/TP02/Exercise1/Recursion.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
public class Recursion {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
if(args.length > 0) {
|
||||||
|
displayFactorial(Integer.parseInt(args[0]));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Usage: java Recursion <number>");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void displayFactorial(int n) {
|
||||||
|
System.out.println(n + "! = " + factorial(n, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int factorial(int n, int count) {
|
||||||
|
count++;
|
||||||
|
System.out.println("n = " + n + " | count = " + count);
|
||||||
|
|
||||||
|
if(n == 0) {
|
||||||
|
//Thread.dumpStack();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n * factorial(n - 1, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
DEV/DEV3.2/TP02/Exercise1/answer.txt
Normal file
14
DEV/DEV3.2/TP02/Exercise1/answer.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
Avec utilisation de dumpStack() :
|
||||||
|
On test pour factoriel de 3, on y voit bien 4 appels :
|
||||||
|
- 3 qui appellent le cas réussit
|
||||||
|
- 1 qui appelle le cas de base
|
||||||
|
|
||||||
|
nathanpasdutout@Macbook-Air-Nathan Exercise1 % java Recursion 3
|
||||||
|
java.lang.Exception: Stack trace
|
||||||
|
at java.base/java.lang.Thread.dumpStack(Thread.java:2209)
|
||||||
|
at Recursion.factorial(Recursion.java:18)
|
||||||
|
at Recursion.factorial(Recursion.java:22)
|
||||||
|
at Recursion.factorial(Recursion.java:22)
|
||||||
|
at Recursion.factorial(Recursion.java:22)
|
||||||
|
at Recursion.displayFactorial(Recursion.java:13)
|
||||||
|
at Recursion.main(Recursion.java:5)
|
||||||
35
DEV/DEV3.2/TP02/Exercise2/ArrayRecursion.java
Normal file
35
DEV/DEV3.2/TP02/Exercise2/ArrayRecursion.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
public class ArrayRecursion {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
displayNumberOfPaireNumber(convertCommandArray(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] convertCommandArray(String[] args) {
|
||||||
|
return convertArray(args, 0, new int[args.length]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int[] convertArray(String[] args, int index, int[] integerArray) {
|
||||||
|
if(index >= args.length) {
|
||||||
|
return integerArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
integerArray[index] = Integer.parseInt(args[index]);
|
||||||
|
return convertArray(args, index + 1, integerArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void displayNumberOfPaireNumber(int[] array) {
|
||||||
|
System.out.println("Nombre de nombres paires : " + getNumberOfPaireNumber(array, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getNumberOfPaireNumber(int[] array, int index) {
|
||||||
|
if(index >= array.length) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(array[index] % 2 == 0) {
|
||||||
|
return getNumberOfPaireNumber(array, index + 1) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getNumberOfPaireNumber(array, index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user