This commit is contained in:
Simoes Lukas
2025-09-24 16:24:52 +02:00
parent 2c3e150ec5
commit 3b7b5533c1
31 changed files with 355 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,18 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ControleurBoutonNon implements ActionListener {
private JDialog fenetre;
public ControleurBoutonNon(JDialog fenetre) {
this.fenetre = fenetre;
}
public void actionPerformed(ActionEvent e) {
fenetre.dispose();
}
}

View File

@@ -0,0 +1,18 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ControleurBoutonOui implements ActionListener {
private JFrame fenetre;
public ControleurBoutonOui(JFrame fenetre) {
this.fenetre = fenetre;
}
public void actionPerformed(ActionEvent e) {
this.fenetre.dispose();
}
}

Binary file not shown.

View File

@@ -0,0 +1,43 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
public class ControleurFenetre implements WindowListener {
private JFrame fenetre;
public ControleurFenetre(JFrame fenetre) {
this.fenetre = fenetre;
}
public void windowClosing(WindowEvent evenement){
JDialog fermeture = new JDialog(this.fenetre, "Fermeture");
fermeture.setLayout(new BorderLayout());
JLabel texte = new JLabel("Voulez-vous vraiment quitter ?");
texte.setHorizontalAlignment(JLabel.CENTER);
fermeture.add(texte, BorderLayout.CENTER);
JPanel panneau = new JPanel();
panneau.setLayout(new FlowLayout());
JButton oui = new JButton("Oui");
oui.addActionListener(new ControleurBoutonOui(this.fenetre));
JButton non = new JButton("Non");
non.addActionListener(new ControleurBoutonNon(fermeture));
panneau.add(oui);
panneau.add(non);
fermeture.add(panneau, BorderLayout.SOUTH);
fermeture.setLocation(400, 275);
fermeture.setSize(300, 100);
fermeture.setVisible(true);
} // avant fermeture
public void windowActivated(WindowEvent evenement) {} // premier plan
public void windowClosed(WindowEvent evenement){} // après fermeture
public void windowDeactivated(WindowEvent evenement){} // arrière-plan
public void windowDeiconified(WindowEvent evenement){} // restauration
public void windowIconified(WindowEvent evenement){} // minimisation
public void windowOpened(WindowEvent evenement){} // après ouverture
}

Binary file not shown.

View 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é
}

Binary file not shown.

View File

@@ -0,0 +1,19 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(900, 450);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setLayout(new GridLayout(1, 1));
JLabel img = new JLabel(new ImageIcon("img1.jpg"));
this.add(img);
this.addMouseListener(new Controlleur(img, this));
this.addWindowListener(new ControleurFenetre(this));
}
}

Binary file not shown.

View File

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

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