tp10
This commit is contained in:
Binary file not shown.
@@ -1,32 +1,39 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.awt.Color.*;
|
|
||||||
|
|
||||||
public class Playlist extends JFrame implements MouseListener{
|
public class Playlist extends JFrame implements MouseListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void mouseClicked(MouseEvent evenement){
|
public void mouseClicked(MouseEvent e) {
|
||||||
evenement.setBackground(COLOR.GREY);
|
this.setBackground(Color.LIGHT_GRAY);
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
void mouseEntered(MouseEvent evenement){
|
|
||||||
evenement.setBackground(COLOR.CYAN);
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
void mouseExited(MouseEvent evenement){
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
@Override
|
||||||
JFrame fenetre = new JFrame();
|
public void mouseEntered(MouseEvent e) {
|
||||||
fenetre.setSize(300, 200);
|
this.setBackground(Color.CYAN);
|
||||||
fenetre.setTitle("Playlist");
|
repaint();
|
||||||
GridLayout grid = new GridLayout(9, 1);
|
}
|
||||||
grid.setVgap(-15);
|
|
||||||
fenetre.setLayout(grid);
|
@Override
|
||||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
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 mus1 = new JLabel("Speak To Me/Breathe");
|
||||||
JLabel mus2 = new JLabel("On The Run");
|
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 mus8 = new JLabel("Brain Damage");
|
||||||
JLabel mus9 = new JLabel("Eclipse");
|
JLabel mus9 = new JLabel("Eclipse");
|
||||||
|
|
||||||
JLabel[] tab = null;
|
JLabel[] tab = {mus1, mus2, mus3, mus4, mus5, mus6, mus7, mus8, mus9};
|
||||||
tab = new JLabel[] {mus1,mus2,mus3,mus4,mus5,mus6,mus7,mus8,mus9};
|
|
||||||
|
|
||||||
for (int i=0; i<9; i++){
|
for (JLabel label : tab) {
|
||||||
mouseClicked(tab[i]);
|
label.addMouseListener(this);
|
||||||
mouseEntered(tab[i]);
|
add(label);
|
||||||
mouseExited(tab[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fenetre.add(mus1);
|
setVisible(true);
|
||||||
fenetre.add(mus2);
|
}
|
||||||
fenetre.add(mus3);
|
|
||||||
fenetre.add(mus4);
|
public static void main(String[] args) {
|
||||||
fenetre.add(mus5);
|
Playlist play = new Playlist();
|
||||||
fenetre.add(mus6);
|
|
||||||
fenetre.add(mus7);
|
|
||||||
fenetre.add(mus8);
|
|
||||||
fenetre.add(mus9);
|
|
||||||
fenetre.setVisible(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
6
DEV2.1/Exception/ex1/NullPointerException.java
Normal file
6
DEV2.1/Exception/ex1/NullPointerException.java
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
6
DEV2.1/Exception/ex1/NumberFormatException.java
Normal file
6
DEV2.1/Exception/ex1/NumberFormatException.java
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
5
DEV2.1/Exception/ex1/RuntimeExceptionExample.java
Normal file
5
DEV2.1/Exception/ex1/RuntimeExceptionExample.java
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
14
DEV2.1/Exception/ex2/ArithmeticExceptionExample.java
Normal file
14
DEV2.1/Exception/ex2/ArithmeticExceptionExample.java
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
9
DEV2.1/Exception/ex2/Main.java
Normal file
9
DEV2.1/Exception/ex2/Main.java
Normal file
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
DEV2.1/Exception/ex3/Incomplet.java
Normal file
13
DEV2.1/Exception/ex3/Incomplet.java
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user