From f7de13bc2aed4c641dcb0f99a971a0cfae2b5276 Mon Sep 17 00:00:00 2001 From: EmmanuelTiamzon Date: Fri, 26 Sep 2025 14:57:00 +0200 Subject: [PATCH] version copilot --- DEV.3.1/TP/TP2/Galerie.1/GFenetre.java | 35 +++++++++------------ DEV.3.1/TP/TP2/Galerie.1/GModel.java | 23 ++++++++++++++ DEV.3.1/TP/TP2/Galerie.1/GestionSouris.java | 24 ++++++++------ DEV.3.1/TP/TP2/Galerie.1/Main.java | 9 ++++++ 4 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 DEV.3.1/TP/TP2/Galerie.1/GModel.java diff --git a/DEV.3.1/TP/TP2/Galerie.1/GFenetre.java b/DEV.3.1/TP/TP2/Galerie.1/GFenetre.java index 5a14a7e..d51c57a 100644 --- a/DEV.3.1/TP/TP2/Galerie.1/GFenetre.java +++ b/DEV.3.1/TP/TP2/Galerie.1/GFenetre.java @@ -2,32 +2,25 @@ import java.awt.*; import javax.swing.*; public class GFenetre extends JFrame { - - private JFrame frame; - private JLabel image1; - private JLabel image2; - private GestionSouris gsouris; + private JLabel imgJLabel; public GFenetre() { - this.frame = new JFrame("Galerie"); - this.image1 = new JLabel(new ImageIcon("image1.jpeg")); //que gif, png et jpeg - this.image2 = new JLabel(new ImageIcon("MICHEL.gif")); - this.gsouris = new GestionSouris(this.image2, this); + super("Galerie"); + this.setSize(1000, 600); + this.setLocationRelativeTo(null); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - this.frame.setSize(1000, 600); - this.frame.setLocation(100,100); - this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - this.image2.setHorizontalAlignment(JLabel.CENTER); - this.frame.add(this.image2, BorderLayout.CENTER); - - this.image2.addMouseListener(this.gsouris); - this.image1.addMouseListener(this.gsouris); + this.imgJLabel = new JLabel(); + this.add(this.imgJLabel, BorderLayout.CENTER); - - - this.frame.setVisible(true); } + public void afficherImage(ImageIcon image) { + this.imgJLabel.setIcon(image); + } + + public JLabel getImageLabel() { + return this.imgJLabel; + } } \ No newline at end of file diff --git a/DEV.3.1/TP/TP2/Galerie.1/GModel.java b/DEV.3.1/TP/TP2/Galerie.1/GModel.java new file mode 100644 index 0000000..3f16efb --- /dev/null +++ b/DEV.3.1/TP/TP2/Galerie.1/GModel.java @@ -0,0 +1,23 @@ +import javax.swing.*; + +public class GModel { + private ImageIcon[] imgCarousel; + private int index; + + public GModel(ImageIcon[] imgCarousel) { + this.imgCarousel = imgCarousel; + this.index = 0; + } + + public ImageIcon getImageActuel() { + return this.imgCarousel[this.index]; + } + + public void imageSuivante() { + this.index = (this.index + 1) % imgCarousel.length; + } + + public void imagePrecedente() { + this.index = (this.index - 1 + this.imgCarousel.length) % imgCarousel.length; + } +} \ No newline at end of file diff --git a/DEV.3.1/TP/TP2/Galerie.1/GestionSouris.java b/DEV.3.1/TP/TP2/Galerie.1/GestionSouris.java index 801c1d6..bb84df5 100644 --- a/DEV.3.1/TP/TP2/Galerie.1/GestionSouris.java +++ b/DEV.3.1/TP/TP2/Galerie.1/GestionSouris.java @@ -4,29 +4,33 @@ import java.awt.event.*; public class GestionSouris implements MouseListener { - private Component component; + private GModel model; private GFenetre gfenetre; - public GestionSouris(Component component, GFenetre gfenetre) { - this.component = component; + public GestionSouris(GModel model, GFenetre gfenetre) { + this.model = model; this.gfenetre = gfenetre; + this.gfenetre.getImageLabel().addMouseListener(this); + this.gfenetre.afficherImage(this.model.getImageActuel()); } @Override public void mouseClicked(MouseEvent e) { int x = e.getX(); - int width = component.getWidth(); + int width = this.gfenetre.getImageLabel().getWidth(); if(x < width / 2) { - //Click à gauche de l'écran - System.out.println("click gauche"); - this.gfenetre.change(0); + this.model.imagePrecedente(); } else { - //Click à droite de l'écran - System.out.println("Click droit"); - this.gfenetre.change(1); + this.model.imageSuivante(); } + + this.gfenetre.remove(this.gfenetre.getImageLabel()); + this.gfenetre.getImageLabel().setIcon(this.model.getImageActuel()); + this.gfenetre.add(this.gfenetre.getImageLabel(), BorderLayout.CENTER); + this.gfenetre.revalidate(); + this.gfenetre.repaint(); } public void mousePressed(MouseEvent e) {} diff --git a/DEV.3.1/TP/TP2/Galerie.1/Main.java b/DEV.3.1/TP/TP2/Galerie.1/Main.java index 15edb4f..fef9417 100644 --- a/DEV.3.1/TP/TP2/Galerie.1/Main.java +++ b/DEV.3.1/TP/TP2/Galerie.1/Main.java @@ -1,5 +1,14 @@ +import java.awt.*; +import javax.swing.*; + public class Main { public static void main(String[] args) { + + ImageIcon[] images = {new ImageIcon("image1.jpeg"), new ImageIcon("image2.jpeg"), new ImageIcon("MICHEL.gif")}; + + GModel model = new GModel(images); GFenetre fenetre = new GFenetre(); + + fenetre.setVisible(true); } } \ No newline at end of file