wow le tp là
This commit is contained in:
52
DEV3.1/TP02/01_Galerie/v1/Controlleur.java
Normal file
52
DEV3.1/TP02/01_Galerie/v1/Controlleur.java
Normal file
@@ -0,0 +1,52 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Controlleur implements MouseListener {
|
||||
|
||||
private JLabel img;
|
||||
private Fenetre fenetre;
|
||||
private String[] images;
|
||||
private int actuel;
|
||||
|
||||
public Controlleur(JLabel img, Fenetre fenetre) {
|
||||
this.img = img;
|
||||
this.fenetre = fenetre;
|
||||
String[] temp = {
|
||||
"img1.jpg",
|
||||
"img2.jpg",
|
||||
"img3.jpg",
|
||||
"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é
|
||||
}
|
Reference in New Issue
Block a user