tp10
This commit is contained in:
Binary file not shown.
@@ -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();
|
||||
}
|
||||
}
|
||||
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