diff --git a/DEV/DEV3.1/TP04/.DS_Store b/DEV/DEV3.1/TP04/.DS_Store new file mode 100644 index 0000000..e3fca77 Binary files /dev/null and b/DEV/DEV3.1/TP04/.DS_Store differ diff --git a/DEV/DEV3.1/TP04/Exercise1/.DS_Store b/DEV/DEV3.1/TP04/Exercise1/.DS_Store new file mode 100644 index 0000000..72269f8 Binary files /dev/null and b/DEV/DEV3.1/TP04/Exercise1/.DS_Store differ diff --git a/DEV/DEV3.1/TP04/Exercise1/Makefile b/DEV/DEV3.1/TP04/Exercise1/Makefile new file mode 100644 index 0000000..cb6a4fe --- /dev/null +++ b/DEV/DEV3.1/TP04/Exercise1/Makefile @@ -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 + + + diff --git a/DEV/DEV3.1/TP04/Exercise1/resources/dice.jpg b/DEV/DEV3.1/TP04/Exercise1/resources/dice.jpg new file mode 100644 index 0000000..9619f77 Binary files /dev/null and b/DEV/DEV3.1/TP04/Exercise1/resources/dice.jpg differ diff --git a/DEV/DEV3.1/TP04/Exercise1/resources/frog.png b/DEV/DEV3.1/TP04/Exercise1/resources/frog.png new file mode 100644 index 0000000..f3c8c99 Binary files /dev/null and b/DEV/DEV3.1/TP04/Exercise1/resources/frog.png differ diff --git a/DEV/DEV3.1/TP04/Exercise1/resources/random.jpg b/DEV/DEV3.1/TP04/Exercise1/resources/random.jpg new file mode 100644 index 0000000..7f1e47c Binary files /dev/null and b/DEV/DEV3.1/TP04/Exercise1/resources/random.jpg differ diff --git a/DEV/DEV3.1/TP04/Exercise1/src/ClickSwapImageEvent.java b/DEV/DEV3.1/TP04/Exercise1/src/ClickSwapImageEvent.java new file mode 100644 index 0000000..75c7755 --- /dev/null +++ b/DEV/DEV3.1/TP04/Exercise1/src/ClickSwapImageEvent.java @@ -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); + } +} diff --git a/DEV/DEV3.1/TP04/Exercise1/src/ImageManager.java b/DEV/DEV3.1/TP04/Exercise1/src/ImageManager.java new file mode 100644 index 0000000..7a8ca60 --- /dev/null +++ b/DEV/DEV3.1/TP04/Exercise1/src/ImageManager.java @@ -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]; + } +} diff --git a/DEV/DEV3.1/TP04/Exercise1/src/ImageWindow.java b/DEV/DEV3.1/TP04/Exercise1/src/ImageWindow.java new file mode 100644 index 0000000..e612645 --- /dev/null +++ b/DEV/DEV3.1/TP04/Exercise1/src/ImageWindow.java @@ -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(); + } +} diff --git a/DEV/DEV3.1/TP04/Exercise1/src/Main.java b/DEV/DEV3.1/TP04/Exercise1/src/Main.java new file mode 100644 index 0000000..172e81e --- /dev/null +++ b/DEV/DEV3.1/TP04/Exercise1/src/Main.java @@ -0,0 +1,9 @@ +package fr.nathanbaudrier; + +public class Main { + + public static void main(String[] args) { + ImageWindow window = new ImageWindow(); + window.setVisible(true); + } +} diff --git a/DEV/DEV3.2/TP01/Exercise1/GenericList.java b/DEV/DEV3.2/TP01/Exercise1/GenericList.java new file mode 100644 index 0000000..d380231 --- /dev/null +++ b/DEV/DEV3.2/TP01/Exercise1/GenericList.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; + +class GenericList { + public static void main(String[] args) { + ArrayList integerList = new ArrayList<>(); // Peut recevoir des Integer + integerList.add(1); + integerList.add(2); + integerList.add(3); + + ArrayList 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 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); + } +} \ No newline at end of file diff --git a/DEV/DEV3.2/TP01/Exercise2/ArrayMethods.java b/DEV/DEV3.2/TP01/Exercise2/ArrayMethods.java new file mode 100644 index 0000000..9eb299e --- /dev/null +++ b/DEV/DEV3.2/TP01/Exercise2/ArrayMethods.java @@ -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) + + } +} diff --git a/DEV/DEV3.2/TP02/Exercise1/Recursion.java b/DEV/DEV3.2/TP02/Exercise1/Recursion.java new file mode 100644 index 0000000..d9ccbe9 --- /dev/null +++ b/DEV/DEV3.2/TP02/Exercise1/Recursion.java @@ -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 "); + } + + 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); + } +} diff --git a/DEV/DEV3.2/TP02/Exercise1/answer.txt b/DEV/DEV3.2/TP02/Exercise1/answer.txt new file mode 100644 index 0000000..537a934 --- /dev/null +++ b/DEV/DEV3.2/TP02/Exercise1/answer.txt @@ -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) \ No newline at end of file diff --git a/DEV/DEV3.2/TP02/Exercise2/ArrayRecursion.java b/DEV/DEV3.2/TP02/Exercise2/ArrayRecursion.java new file mode 100644 index 0000000..c5ddb82 --- /dev/null +++ b/DEV/DEV3.2/TP02/Exercise2/ArrayRecursion.java @@ -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); + } +}