From cd3133cbe197172e532532b9b8a1aa41c65b73e1 Mon Sep 17 00:00:00 2001 From: Felix-Vimalaratnam Date: Mon, 18 Mar 2024 14:28:35 +0100 Subject: [PATCH] tp10 --- DEV2.1/Evenement_suite/Playlist.class | Bin 1127 -> 1786 bytes DEV2.1/Evenement_suite/Playlist.java | 74 +++++++++--------- .../Exception/ex1/NullPointerException.java | 6 ++ .../Exception/ex1/NumberFormatException.java | 6 ++ .../ex1/RuntimeExceptionExample.java | 5 ++ .../ex2/ArithmeticExceptionExample.java | 14 ++++ DEV2.1/Exception/ex2/Main.java | 9 +++ DEV2.1/Exception/ex3/Incomplet.java | 13 +++ 8 files changed, 90 insertions(+), 37 deletions(-) create mode 100644 DEV2.1/Exception/ex1/NullPointerException.java create mode 100644 DEV2.1/Exception/ex1/NumberFormatException.java create mode 100644 DEV2.1/Exception/ex1/RuntimeExceptionExample.java create mode 100644 DEV2.1/Exception/ex2/ArithmeticExceptionExample.java create mode 100644 DEV2.1/Exception/ex2/Main.java create mode 100644 DEV2.1/Exception/ex3/Incomplet.java diff --git a/DEV2.1/Evenement_suite/Playlist.class b/DEV2.1/Evenement_suite/Playlist.class index 6f677ce80b52296ce433c038de424e9cb414ab7c..fcf7f96c39388be8d3a550004b31416bc6394c84 100644 GIT binary patch literal 1786 zcmX^0Z`VEs1_pD6Bu)l>1_Lez83scTVFcnDg9sB222(BuP6jiOusJ(}1&Fp}XRzX8 z;AXG}actNbY&jV0xES~t%s3eAIT#!`7#ukmoH!VqIT&0x7+g6R+(44qD^PG)j;Y6>HRoQ6+UVp*boVtI*vYFTPtiM}sL-W9~O)(m50 zU~$e*No8c<_sPsl^()OyN-YXWOv*`x8RVK*l3D~Zh#PFKYei-WhzGGHpeVJt7{uiT zO9rLpq$Yy-Y&MyBnI(3N49prJJ9vXj5|gui6AQpbvorWGGO*+(X67+6h-pMa+?SJ> zm#!aNQk0pO4t5q-aDHh~a;jS<$SJ%5If<1ynZ+e~AiuCP`0_CLG5GT^1TX~h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J0-P+{8901(1U_zK;MCUH z#=xb`wvB;%H$y#7q!90R20p*t3_OuS{M#A$tXRNI0T7cF%oGGM*}zO85R)Cu6b3Ol zz)TSklM~Do1u?n6Ofe9XTU&PSds(6<%CdN5Q-a2v20_I zKm 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(); + } + } +}