diff --git a/DEV2.1/Evenement_suite/Playlist.class b/DEV2.1/Evenement_suite/Playlist.class index 6f677ce..fcf7f96 100644 Binary files a/DEV2.1/Evenement_suite/Playlist.class and b/DEV2.1/Evenement_suite/Playlist.class differ diff --git a/DEV2.1/Evenement_suite/Playlist.java b/DEV2.1/Evenement_suite/Playlist.java index ee25b00..4048d60 100644 --- a/DEV2.1/Evenement_suite/Playlist.java +++ b/DEV2.1/Evenement_suite/Playlist.java @@ -1,32 +1,39 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; -import java.awt.Color.*; -public class Playlist extends JFrame implements MouseListener{ +public class Playlist extends JFrame implements MouseListener { + @Override - void mouseClicked(MouseEvent evenement){ - evenement.setBackground(COLOR.GREY); - repaint(); - } - @Override - void mouseEntered(MouseEvent evenement){ - evenement.setBackground(COLOR.CYAN); - repaint(); - } - @Override - void mouseExited(MouseEvent evenement){ + public void mouseClicked(MouseEvent e) { + this.setBackground(Color.LIGHT_GRAY); repaint(); } - public static void main(String[] args) { - JFrame fenetre = new JFrame(); - fenetre.setSize(300, 200); - fenetre.setTitle("Playlist"); - GridLayout grid = new GridLayout(9, 1); - grid.setVgap(-15); - fenetre.setLayout(grid); - fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + @Override + public void mouseEntered(MouseEvent e) { + this.setBackground(Color.CYAN); + repaint(); + } + + @Override + public void mouseExited(MouseEvent e) { + this.setBackground(Color.WHITE); + repaint(); + } + + // Les méthodes suivantes ne sont pas utilisées mais doivent être implémentées en raison de l'interface MouseListener + @Override + public void mousePressed(MouseEvent e) {} + + @Override + public void mouseReleased(MouseEvent e) {} + + public Playlist() { + super("Playlist"); + setSize(300, 200); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLayout(new GridLayout(9, 1)); JLabel mus1 = new JLabel("Speak To Me/Breathe"); JLabel mus2 = new JLabel("On The Run"); @@ -38,24 +45,17 @@ public class Playlist extends JFrame implements MouseListener{ JLabel mus8 = new JLabel("Brain Damage"); JLabel mus9 = new JLabel("Eclipse"); - JLabel[] tab = null; - tab = new JLabel[] {mus1,mus2,mus3,mus4,mus5,mus6,mus7,mus8,mus9}; + JLabel[] tab = {mus1, mus2, mus3, mus4, mus5, mus6, mus7, mus8, mus9}; - for (int i=0; i<9; i++){ - mouseClicked(tab[i]); - mouseEntered(tab[i]); - mouseExited(tab[i]); + for (JLabel label : tab) { + label.addMouseListener(this); + add(label); } - fenetre.add(mus1); - fenetre.add(mus2); - fenetre.add(mus3); - fenetre.add(mus4); - fenetre.add(mus5); - fenetre.add(mus6); - fenetre.add(mus7); - fenetre.add(mus8); - fenetre.add(mus9); - fenetre.setVisible(true); + setVisible(true); + } + + public static void main(String[] args) { + Playlist play = new Playlist(); } } \ No newline at end of file diff --git a/DEV2.1/Exception/ex1/NullPointerException.java b/DEV2.1/Exception/ex1/NullPointerException.java new file mode 100644 index 0000000..5649d20 --- /dev/null +++ b/DEV2.1/Exception/ex1/NullPointerException.java @@ -0,0 +1,6 @@ +public class NullPointerException { + public static void main(String[] args) { + String str = null; + int length = str.length(); // Tentative d'accéder à une méthode sur un objet nul + } +} diff --git a/DEV2.1/Exception/ex1/NumberFormatException.java b/DEV2.1/Exception/ex1/NumberFormatException.java new file mode 100644 index 0000000..8206e3b --- /dev/null +++ b/DEV2.1/Exception/ex1/NumberFormatException.java @@ -0,0 +1,6 @@ +public class NumberFormatException { + public static void main(String[] args) { + String str = "abc"; + int num = Integer.parseInt(str); // Conversion d'une chaîne non numérique en entier + } +} diff --git a/DEV2.1/Exception/ex1/RuntimeExceptionExample.java b/DEV2.1/Exception/ex1/RuntimeExceptionExample.java new file mode 100644 index 0000000..3913436 --- /dev/null +++ b/DEV2.1/Exception/ex1/RuntimeExceptionExample.java @@ -0,0 +1,5 @@ +public class RuntimeExceptionExample { + public static void main(String[] args) { + throw new UnsupportedOperationException("Operation not supported"); // Lancement d'une exception d'opération non supportée + } +} diff --git a/DEV2.1/Exception/ex2/ArithmeticExceptionExample.java b/DEV2.1/Exception/ex2/ArithmeticExceptionExample.java new file mode 100644 index 0000000..894b5e1 --- /dev/null +++ b/DEV2.1/Exception/ex2/ArithmeticExceptionExample.java @@ -0,0 +1,14 @@ +public class ArithmeticExceptionExample { + public static void main(String[] args) { + try { + computeDivision(); // Appel de la méthode responsable de l'exception + } catch (ArithmeticException e) { + System.out.println("Une erreur arithmétique s'est produite : " + e.getMessage()); + } + } + + // Méthode responsable de l'exception + public static void computeDivision() { + int result = 10 / 0; // Division par zéro + } +} diff --git a/DEV2.1/Exception/ex2/Main.java b/DEV2.1/Exception/ex2/Main.java new file mode 100644 index 0000000..f968057 --- /dev/null +++ b/DEV2.1/Exception/ex2/Main.java @@ -0,0 +1,9 @@ +public class Main { + public static void main(String[] args) { + try { + ArithmeticExceptionVrai.computeDivision(); + } catch (ArithmeticException e) { + System.out.println("Une erreur arithmétique s'est produite : " + e.getMessage()); + } + } +} diff --git a/DEV2.1/Exception/ex3/Incomplet.java b/DEV2.1/Exception/ex3/Incomplet.java new file mode 100644 index 0000000..4c53eef --- /dev/null +++ b/DEV2.1/Exception/ex3/Incomplet.java @@ -0,0 +1,13 @@ +import java.io.IOException; + +public class Incomplet { + public static void main(String[] args) { + byte[] txt = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x0D, 0x0A}; + try { + System.out.write(txt); + System.out.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } +}