ajout tp4

This commit is contained in:
Simoes Lukas
2025-09-25 14:02:11 +02:00
parent 3b7b5533c1
commit 3393bcafca
24 changed files with 88 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

View File

@@ -0,0 +1,55 @@
package fr.iutfbleau.galerie;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.net.URL;
public class Controlleur implements MouseListener {
private JLabel img;
private Fenetre fenetre;
private URL[] images;
private int actuel;
public Controlleur(JLabel img, Fenetre fenetre) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
this.img = img;
this.fenetre = fenetre;
URL[] temp = {
loader.getResource("res/img1.jpg"),
loader.getResource("res/img2.jpg"),
loader.getResource("res/img3.jpg"),
loader.getResource("res/img4.jpg")
};
this.images = temp;
this.actuel = 0;
}
public void mouseClicked(MouseEvent evenement) {
if (evenement.getX() < this.fenetre.getWidth()/2) {
this.actuel--;
if (this.actuel == -1) {
this.actuel = 3;
}
}
else {
this.actuel++;
if (this.actuel == 4) {
this.actuel = 0;
}
}
this.fenetre.getContentPane().removeAll();
this.fenetre.add(new JLabel(new ImageIcon(this.images[this.actuel])));
this.fenetre.revalidate();
this.fenetre.repaint();
} // un bouton cliqué
public void mouseEntered(MouseEvent evenement) {} // debut du survol
public void mouseExited(MouseEvent evenement) {} // fin du survol
public void mousePressed(MouseEvent evenement) {} // un bouton appuyé
public void mouseReleased(MouseEvent evenement) {} // un bouton relâché
}

View File

@@ -0,0 +1,21 @@
package fr.iutfbleau.galerie;
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(900, 450);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(1, 1));
ClassLoader loader = Thread.currentThread().getContextClassLoader();
JLabel img = new JLabel(new ImageIcon(loader.getResource("res/img1.jpg")));
this.add(img);
this.addMouseListener(new Controlleur(img, this));
}
}

View File

@@ -0,0 +1,8 @@
package fr.iutfbleau.galerie;
public class Main {
public static void main(String[] args) {
Fenetre fenetre = new Fenetre();
fenetre.setVisible(true);
}
}

View File

@@ -0,0 +1,4 @@
Manifest-Version: 1.0
Created-By: 11.0.27 (Arch Linux)
Main-Class: fr.iutfbleau.galerie.Main

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB