first commit
96
TP_DEV3.1/Base de donnée/Vote.java
Normal file
@@ -0,0 +1,96 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.mariadb.jdbc.*;
|
||||
|
||||
public class Vote {
|
||||
|
||||
private static final String lien = "jdbc:mariadb://dwarves.iut-fbleau.fr/yolou";
|
||||
private static final String user = "yolou";
|
||||
private static final String mdp = "serikhanejunior";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
|
||||
|
||||
if(args.length !=1 ){
|
||||
|
||||
System.err.println("Met un seul pays ");
|
||||
System.exit(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
String pays = args[0];
|
||||
|
||||
try {
|
||||
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
}catch(ClassNotFoundException e) {
|
||||
|
||||
System.err.println("Il y'a pas de DriverManager Maria DB");
|
||||
}
|
||||
|
||||
String requete_sql = "Select pays_votant as votant, p.points" +
|
||||
"FROM Points p " +
|
||||
"JOIN Competiteur c ON p.competiteur_id = c.id " +
|
||||
"JOIN Votant v ON p.votant_id = v.id " +
|
||||
"WHERE c.pays = ? " +
|
||||
"ORDER BY v.pays_votant";
|
||||
|
||||
String totalSql =
|
||||
"SELECT SUM(p.points) " +
|
||||
"FROM Points p " +
|
||||
"JOIN Competiteur c ON p.competiteur_id = c.id " +
|
||||
"WHERE c.pays = ?";
|
||||
|
||||
Connection cnx = DriverManager.getConnection(lien, user, mdp);
|
||||
PreparedStatement pst = cnx.prepareStatement(requete_sql);
|
||||
PreparedStatement pstTotal = cnx.prepareStatement(totalSql);
|
||||
|
||||
pst.setString(1, pays);
|
||||
try (ResultSet rs = pst.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
String votant = rs.getString("votant");
|
||||
int pts = rs.getInt("points");
|
||||
System.out.printf("%-10s %d%n", votant, pts);
|
||||
}
|
||||
}
|
||||
|
||||
pstTotal.setString(1, pays);
|
||||
try (ResultSet rsT = pstTotal.executeQuery()) {
|
||||
rsT.next();
|
||||
int total = rsT.getInt(1);
|
||||
System.out.println("---------");
|
||||
System.out.println("Total " + total);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Erreur SQL : " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
37
TP_DEV3.1/Base de donnée/sql.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
-- Table des pays
|
||||
|
||||
CREATE TABLE Pays_vote (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
nom VARCHAR(50) UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
-- Table des votes
|
||||
|
||||
CREATE TABLE Vote (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
paysfrom_id INT NOT NULL, -- pays qui vote
|
||||
paysto_id INT NOT NULL, -- pays qui reçoit
|
||||
nb_points INT NOT NULL,
|
||||
FOREIGN KEY (paysfrom_id) REFERENCES Pays_vote(id),
|
||||
FOREIGN KEY (paysto_id) REFERENCES Pays_vote(id)
|
||||
);
|
||||
|
||||
-- Insertion des pays
|
||||
insert into Pays_vote (nom) values ('Pays-Bas'), ('Italie'), ('Russie');
|
||||
|
||||
-- Récupération automatique des id (supposons)
|
||||
-- Pays-Bas = 1, Italie = 2, Russie = 3
|
||||
|
||||
-- Insertion des votes (avec id)
|
||||
VALUES
|
||||
(2, 1, 5), -- Italie → Pays-Bas = 5
|
||||
(3, 1, 5), -- Russie → Pays-Bas = 5
|
||||
(1, 2, 16), -- Pays-Bas → Italie = 16
|
||||
(3, 2, 1), -- Russie → Italie = 1
|
||||
(1, 3, 5), -- Pays-Bas → Russie = 5
|
||||
(2, 3, 8); -- Italie → Russie = 8
|
||||
|
||||
Insert into Vote (paysfrom_id,paysto_id,nb_points) values (2,1,5), (3,1,5), (1,2,16), (3,2,1), (1,3,5), (2,3,8);
|
||||
|
||||
javac -cp .:/export/documents/mariadb-client.jar Vote.java
|
||||
java -cp .:/export/documents/mariadb-client.jar:. Vote Italie
|
||||
18
TP_DEV3.1/ControllerSouris.java
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
|
||||
public class ControllerSouris extend Galerie {
|
||||
|
||||
public ControllerSouris(){
|
||||
super();
|
||||
|
||||
}
|
||||
|
||||
public void imageSuivante(){
|
||||
|
||||
indexImage = (indexImage+1)%listeimage.length();
|
||||
etiquetteImage.setIcon()
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
72
TP_DEV3.1/Organisation du code/AppGalerie.java
Normal file
@@ -0,0 +1,72 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
package fr.iutfbleau.projet;
|
||||
|
||||
public class AppGalerie extends JFrame implements MouseListener{
|
||||
|
||||
|
||||
private String[] listeimage = {"image1.png","image2.png","image4.png"};
|
||||
private int IndexImage = 0;
|
||||
private JPanel panneau = new JPanel(new BorderLayout());
|
||||
// private JFrame fenetre = new JFrame();
|
||||
private JLabel etiquetteImage = new JLabel();
|
||||
|
||||
public Galerie() {
|
||||
|
||||
|
||||
|
||||
|
||||
super("Confirmation");
|
||||
|
||||
etiquetteImage.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
etiquetteImage.setIcon(new ImageIcon(listeimage[IndexImage]));
|
||||
|
||||
panneau.add(etiquetteImage, BorderLayout.CENTER);
|
||||
panneau.addMouseListener(this);
|
||||
setContentPane(panneau);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {} // Appui sur le bouton de la souris
|
||||
|
||||
public void mouseReleased(MouseEvent e) {} // Relâchement du bouton
|
||||
|
||||
public void mouseEntered(MouseEvent e) {} // Souris entre dans le composant
|
||||
|
||||
|
||||
public void mouseExited(MouseEvent e) {} // Souris sort du composant
|
||||
|
||||
public void mouseClicked(MouseEvent e){
|
||||
|
||||
int largeurpanel = panneau.getWidth();
|
||||
|
||||
if(e.getX () > largeurpanel/2 ){
|
||||
|
||||
imageSuivante();
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
imagePrecedente();
|
||||
}
|
||||
}
|
||||
|
||||
private void imageSuivante() {
|
||||
IndexImage = (IndexImage + 1) % listeimage.length;
|
||||
etiquetteImage.setIcon(new ImageIcon(listeimage[IndexImage]));
|
||||
}
|
||||
|
||||
private void imagePrecedente() {
|
||||
IndexImage = (IndexImage - 1 + listeimage.length) % listeimage.length;
|
||||
etiquetteImage.setIcon(new ImageIcon(listeimage[IndexImage]));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
AppGalerie test = new Galerie();
|
||||
|
||||
test.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
10
TP_DEV3.1/Organisation du code/GalerieTest.java
Normal file
@@ -0,0 +1,10 @@
|
||||
public class GalerieTest {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
AppGalerie test = new Galerie();
|
||||
|
||||
test.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package fr.iutflbeau.projet.view;
|
||||
import fr.iutfbleau.projet.controller.ValidationChoix;
|
||||
import fr.iutfbleau.projet.modele.*;
|
||||
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
|
||||
public class FenetreQuizz extends JFrame implements ActionListener {
|
||||
|
||||
private Question[] questionsquiz;
|
||||
private ChoixUitlisateur choix;
|
||||
private int index = 0;
|
||||
private boolean valide = false;
|
||||
|
||||
private JPanel zoneCentre new JPanel(new BorderLayout());
|
||||
private JButton boutonPrecedent = new JButton("Précédent");
|
||||
private JButton boutonSuivant = new JButton("Suivant");
|
||||
private JButton boutonValider = new JButton("Valider");
|
||||
|
||||
private EcranQuestion EcranDeBase;
|
||||
|
||||
public FenetreQuizz(Question[] questionsquiz) {
|
||||
|
||||
|
||||
super("QCM");
|
||||
this.questionsquiz = questionsquiz;
|
||||
this.choix = new ChoixUitlisateur(questionsquiz.length);
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(zoneCentre, BorderLayout.CENTER);
|
||||
|
||||
boutonSuivant.addActionListener(this);
|
||||
boutonPrecedent.addActionListener(this);
|
||||
boutonValider.addActionListener(this);
|
||||
|
||||
mettreAJourEcran();
|
||||
|
||||
this.setSize(520, 320);
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e){
|
||||
|
||||
Object source = e.getSource();
|
||||
|
||||
|
||||
if(source == boutonPrecedent){
|
||||
|
||||
AllerPrecedent();
|
||||
|
||||
}
|
||||
|
||||
if(source == boutonSuivant){
|
||||
|
||||
AllerSuivant();
|
||||
}
|
||||
|
||||
if(source == boutonValider) {
|
||||
|
||||
Valider();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
BIN
TP_DEV3.1/Organisation du code/projet/AppGalerie.jar
Normal file
BIN
TP_DEV3.1/Organisation du code/projet/build/images/image1.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
TP_DEV3.1/Organisation du code/projet/build/images/image2.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
TP_DEV3.1/Organisation du code/projet/build/images/image4.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
TP_DEV3.1/Organisation du code/projet/projet.jar
Normal file
BIN
TP_DEV3.1/Organisation du code/projet/res/images/image1.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
TP_DEV3.1/Organisation du code/projet/res/images/image2.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
TP_DEV3.1/Organisation du code/projet/res/images/image4.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
@@ -0,0 +1,72 @@
|
||||
package fr.iutfbleau.projet;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.net.URL;
|
||||
|
||||
public class AppGalerie extends JFrame implements MouseListener {
|
||||
|
||||
// 1) Chemins DANS LE JAR (=> classpath)
|
||||
private String[] listeImage = {
|
||||
"images/image1.png",
|
||||
"images/image2.png",
|
||||
"images/image4.png"
|
||||
};
|
||||
private int indexImage = 0;
|
||||
|
||||
private JPanel panneau = new JPanel(new BorderLayout());
|
||||
private JLabel etiquetteImage = new JLabel();
|
||||
|
||||
public AppGalerie() {
|
||||
super("Confirmation");
|
||||
|
||||
etiquetteImage.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
etiquetteImage.setIcon(chargerIcone(listeImage[indexImage])); // <-- ICI
|
||||
|
||||
panneau.add(etiquetteImage, BorderLayout.CENTER);
|
||||
panneau.addMouseListener(this);
|
||||
|
||||
setContentPane(panneau);
|
||||
setSize(800, 600);
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
// === MouseListener ===
|
||||
@Override public void mouseClicked(MouseEvent e) {
|
||||
int largeurPanel = panneau.getWidth();
|
||||
if (e.getX() >= largeurPanel / 2) imageSuivante();
|
||||
else imagePrecedente();
|
||||
}
|
||||
@Override public void mousePressed(MouseEvent e) {}
|
||||
@Override public void mouseReleased(MouseEvent e) {}
|
||||
@Override public void mouseEntered(MouseEvent e) {}
|
||||
@Override public void mouseExited(MouseEvent e) {}
|
||||
|
||||
// === Navigation ===
|
||||
private void imageSuivante() {
|
||||
indexImage = (indexImage + 1) % listeImage.length;
|
||||
etiquetteImage.setIcon(chargerIcone(listeImage[indexImage])); // <-- ICI
|
||||
}
|
||||
private void imagePrecedente() {
|
||||
indexImage = (indexImage - 1 + listeImage.length) % listeImage.length;
|
||||
etiquetteImage.setIcon(chargerIcone(listeImage[indexImage])); // <-- ICI
|
||||
}
|
||||
|
||||
// === CHARGEMENT VIA CLASSPATH ===
|
||||
private ImageIcon chargerIcone(String cheminDansJar) {
|
||||
URL url = getClass().getClassLoader().getResource(cheminDansJar);
|
||||
if (url == null) {
|
||||
// debug utile si un nom est faux
|
||||
throw new IllegalArgumentException("Ressource introuvable: " + cheminDansJar);
|
||||
}
|
||||
return new ImageIcon(url);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
AppGalerie test = new AppGalerie();
|
||||
|
||||
test.setVisible(true);
|
||||
}
|
||||
}
|
||||
70
TP_DEV3.1/Organisation du code/test/AppGalerie.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package fr.iutfbleau.projet;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.net.URL;
|
||||
|
||||
public class AppGalerie extends JFrame implements MouseListener {
|
||||
|
||||
// 1) Chemins DANS LE JAR (=> classpath)
|
||||
private String[] listeImage = {
|
||||
"images/image1.png",
|
||||
"images/image2.png",
|
||||
"images/image4.png"
|
||||
};
|
||||
private int indexImage = 0;
|
||||
|
||||
private JPanel panneau = new JPanel(new BorderLayout());
|
||||
private JLabel etiquetteImage = new JLabel();
|
||||
|
||||
public AppGalerie() {
|
||||
super("Confirmation");
|
||||
|
||||
etiquetteImage.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
etiquetteImage.setIcon(chargerIcone(listeImage[indexImage])); // <-- ICI
|
||||
|
||||
panneau.add(etiquetteImage, BorderLayout.CENTER);
|
||||
panneau.addMouseListener(this);
|
||||
|
||||
setContentPane(panneau);
|
||||
setSize(800, 600);
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
// === MouseListener ===
|
||||
@Override public void mouseClicked(MouseEvent e) {
|
||||
int largeurPanel = panneau.getWidth();
|
||||
if (e.getX() >= largeurPanel / 2) imageSuivante();
|
||||
else imagePrecedente();
|
||||
}
|
||||
@Override public void mousePressed(MouseEvent e) {}
|
||||
@Override public void mouseReleased(MouseEvent e) {}
|
||||
@Override public void mouseEntered(MouseEvent e) {}
|
||||
@Override public void mouseExited(MouseEvent e) {}
|
||||
|
||||
// === Navigation ===
|
||||
private void imageSuivante() {
|
||||
indexImage = (indexImage + 1) % listeImage.length;
|
||||
etiquetteImage.setIcon(chargerIcone(listeImage[indexImage])); // <-- ICI
|
||||
}
|
||||
private void imagePrecedente() {
|
||||
indexImage = (indexImage - 1 + listeImage.length) % listeImage.length;
|
||||
etiquetteImage.setIcon(chargerIcone(listeImage[indexImage])); // <-- ICI
|
||||
}
|
||||
|
||||
// === CHARGEMENT VIA CLASSPATH ===
|
||||
private ImageIcon chargerIcone(String cheminDansJar) {
|
||||
URL url = getClass().getClassLoader().getResource(cheminDansJar);
|
||||
if (url == null) {
|
||||
// debug utile si un nom est faux
|
||||
throw new IllegalArgumentException("Ressource introuvable: " + cheminDansJar);
|
||||
}
|
||||
return new ImageIcon(url);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> new AppGalerie().setVisible(true));
|
||||
}
|
||||
}
|
||||
BIN
TP_DEV3.1/Transitions/Galerie.class
Normal file
65
TP_DEV3.1/Transitions/Galerie.java
Normal file
@@ -0,0 +1,65 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Galerie extends JFrame implements MouseListener{
|
||||
|
||||
|
||||
private String[] listeimage = {"image1.png","image2.png","image4.png"};
|
||||
private int IndexImage = 0;
|
||||
private JPanel panneau = new JPanel(new BorderLayout());
|
||||
// private JFrame fenetre = new JFrame();
|
||||
private JLabel etiquetteImage = new JLabel();
|
||||
|
||||
public Galerie() {
|
||||
|
||||
|
||||
|
||||
|
||||
super("Confirmation");
|
||||
|
||||
etiquetteImage.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
etiquetteImage.setIcon(new ImageIcon(listeimage[IndexImage]));
|
||||
|
||||
panneau.add(etiquetteImage, BorderLayout.CENTER);
|
||||
panneau.addMouseListener(this);
|
||||
setContentPane(panneau);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {} // Appui sur le bouton de la souris
|
||||
|
||||
public void mouseReleased(MouseEvent e) {} // Relâchement du bouton
|
||||
|
||||
public void mouseEntered(MouseEvent e) {} // Souris entre dans le composant
|
||||
|
||||
|
||||
public void mouseExited(MouseEvent e) {} // Souris sort du composant
|
||||
|
||||
public void mouseClicked(MouseEvent e){
|
||||
|
||||
int largeurpanel = panneau.getWidth();
|
||||
|
||||
if(e.getX () > largeurpanel/2 ){
|
||||
|
||||
imageSuivante();
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
imagePrecedente();
|
||||
}
|
||||
}
|
||||
|
||||
private void imageSuivante() {
|
||||
IndexImage = (IndexImage + 1) % listeimage.length;
|
||||
etiquetteImage.setIcon(new ImageIcon(listeimage[IndexImage]));
|
||||
}
|
||||
|
||||
private void imagePrecedente() {
|
||||
IndexImage = (IndexImage - 1 + listeimage.length) % listeimage.length;
|
||||
etiquetteImage.setIcon(new ImageIcon(listeimage[IndexImage]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
94
TP_DEV3.1/Transitions/GalerieSimple.java
Normal file
@@ -0,0 +1,94 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class GalerieSimple extends JFrame {
|
||||
|
||||
// Tableau des fichiers images
|
||||
private String[] fichiers = { "img1.jpg", "img2.jpg", "img3.jpg", "img4.jpg" };
|
||||
private int indiceImage = 0;
|
||||
|
||||
// Composants graphiques
|
||||
private JLabel etiquetteImage = new JLabel();
|
||||
|
||||
public GalerieSimple() {
|
||||
super("Galerie avec Confirmation");
|
||||
|
||||
// Affichage de la première image
|
||||
etiquetteImage.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
etiquetteImage.setIcon(new ImageIcon(fichiers[indiceImage]));
|
||||
|
||||
// Panneau principal
|
||||
JPanel panneau = new JPanel(new BorderLayout());
|
||||
panneau.add(etiquetteImage, BorderLayout.CENTER);
|
||||
|
||||
// Clic souris → suivant ou précédent
|
||||
panneau.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int largeur = panneau.getWidth();
|
||||
if (e.getX() >= largeur / 2) {
|
||||
imageSuivante();
|
||||
} else {
|
||||
imagePrecedente();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Fermeture personnalisée (on demande confirmation)
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
demanderConfirmation();
|
||||
}
|
||||
});
|
||||
|
||||
// Paramètres de la fenêtre
|
||||
setContentPane(panneau);
|
||||
setSize(800, 600);
|
||||
setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
private void imageSuivante() {
|
||||
indiceImage = (indiceImage + 1) % fichiers.length;
|
||||
etiquetteImage.setIcon(new ImageIcon(fichiers[indiceImage]));
|
||||
}
|
||||
|
||||
private void imagePrecedente() {
|
||||
indiceImage = (indiceImage - 1 + fichiers.length) % fichiers.length;
|
||||
etiquetteImage.setIcon(new ImageIcon(fichiers[indiceImage]));
|
||||
}
|
||||
|
||||
private void demanderConfirmation() {
|
||||
// Fenêtre modale faite avec JDialog
|
||||
JDialog dialogue = new JDialog(this, "Confirmation", true);
|
||||
dialogue.setLayout(new BorderLayout());
|
||||
|
||||
JLabel message = new JLabel("Voulez-vous quitter ?", SwingConstants.CENTER);
|
||||
JPanel panneauBoutons = new JPanel();
|
||||
|
||||
JButton boutonOui = new JButton("Oui");
|
||||
JButton boutonNon = new JButton("Non");
|
||||
|
||||
panneauBoutons.add(boutonOui);
|
||||
panneauBoutons.add(boutonNon);
|
||||
|
||||
dialogue.add(message, BorderLayout.CENTER);
|
||||
dialogue.add(panneauBoutons, BorderLayout.SOUTH);
|
||||
|
||||
boutonOui.addActionListener(ev -> System.exit(0));
|
||||
boutonNon.addActionListener(ev -> dialogue.dispose());
|
||||
|
||||
dialogue.setSize(300, 150);
|
||||
dialogue.setLocationRelativeTo(this);
|
||||
dialogue.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
GalerieSimple fenetre = new GalerieSimple();
|
||||
fenetre.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
TP_DEV3.1/Transitions/GalerieTest.class
Normal file
10
TP_DEV3.1/Transitions/GalerieTest.java
Normal file
@@ -0,0 +1,10 @@
|
||||
public class GalerieTest {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Galerie test = new Galerie();
|
||||
|
||||
test.setVisible(true);
|
||||
}
|
||||
}
|
||||
27
TP_DEV3.1/Transitions/ListeImage.java
Normal file
@@ -0,0 +1,27 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
public class ListeImage {
|
||||
|
||||
private final String[]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
BIN
TP_DEV3.1/Transitions/image1.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
TP_DEV3.1/Transitions/image2.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
TP_DEV3.1/Transitions/image4.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
15
TP_DEV3.1/Transitions/src/galerie/app/MainCardLayout.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package galerie.app;
|
||||
|
||||
import galerie.model.ImageList;
|
||||
import galerie.view.GalleryCardLayoutFrame;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MainCardLayout {
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
ImageList model = new ImageList("img1.jpg","img2.jpg","img3.jpg","img4.jpg");
|
||||
new GalleryCardLayoutFrame(model).setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
15
TP_DEV3.1/Transitions/src/galerie/app/MainReplacement.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package galerie.app;
|
||||
|
||||
import galerie.model.ImageList;
|
||||
import galerie.view.GalleryReplacementFrame;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class MainReplacement {
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
ImageList model = new ImageList("img1.jpg","img2.jpg","img3.jpg","img4.jpg");
|
||||
new GalleryReplacementFrame(model).setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package galerie.app;
|
||||
|
||||
import galerie.model.ImageList;
|
||||
import galerie.view.GalleryCardLayoutFrame;
|
||||
import galerie.view.ConfirmOnCloseDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class MainWithConfirmation {
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
ImageList model = new ImageList("img1.jpg","img2.jpg","img3.jpg","img4.jpg");
|
||||
JFrame frame = new GalleryCardLayoutFrame(model);
|
||||
|
||||
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override public void windowClosing(WindowEvent e) {
|
||||
ConfirmOnCloseDialog dlg = new ConfirmOnCloseDialog(frame,
|
||||
new ConfirmOnCloseDialog.ResultHandler() {
|
||||
@Override public void onYes() { System.exit(0); }
|
||||
@Override public void onNo() { }
|
||||
});
|
||||
dlg.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
frame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package galerie.control;
|
||||
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Rôle unique : convertir un clic gauche/droite (moitié de composant)
|
||||
* en action "next" ou "previous".
|
||||
*/
|
||||
public class HalfClickNavigator extends MouseAdapter {
|
||||
private final JComponent surface;
|
||||
private final Runnable onNext;
|
||||
private final Runnable onPrevious;
|
||||
|
||||
public HalfClickNavigator(JComponent surface, Runnable onNext, Runnable onPrevious) {
|
||||
this.surface = surface;
|
||||
this.onNext = onNext;
|
||||
this.onPrevious = onPrevious;
|
||||
}
|
||||
|
||||
@Override public void mouseClicked(MouseEvent e) {
|
||||
int w = surface.getWidth();
|
||||
if (e.getX() >= w / 2) onNext.run();
|
||||
else onPrevious.run();
|
||||
}
|
||||
}
|
||||
36
TP_DEV3.1/Transitions/src/galerie/model/ImageList.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package galerie.model;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ImageList {
|
||||
private final String[] files;
|
||||
private int index = 0;
|
||||
|
||||
public ImageList(String... files) {
|
||||
if (files == null || files.length == 0) {
|
||||
throw new IllegalArgumentException("Il faut au moins une image.");
|
||||
}
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
public Icon currentIcon() {
|
||||
return new ImageIcon(files[index]);
|
||||
}
|
||||
|
||||
public void next() {
|
||||
index = (index + 1) % files.length;
|
||||
}
|
||||
|
||||
|
||||
public void previous() {
|
||||
index = (index - 1 + files.length) % files.length;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return files.length;
|
||||
}
|
||||
|
||||
public Icon iconAt(int i) {
|
||||
return new ImageIcon(files[i]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package galerie.view;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ConfirmOnCloseDialog extends JDialog {
|
||||
|
||||
public interface ResultHandler { void onYes(); void onNo(); }
|
||||
|
||||
public ConfirmOnCloseDialog(JFrame parent, ResultHandler handler) {
|
||||
super(parent, "Quitter l'application ?", true);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
JPanel content = new JPanel(new BorderLayout(10,10));
|
||||
content.setBorder(BorderFactory.createEmptyBorder(12,12,12,12));
|
||||
JLabel msg = new JLabel("Voulez-vous vraiment quitter ?", SwingConstants.CENTER);
|
||||
|
||||
JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
JButton yes = new JButton("Oui");
|
||||
JButton no = new JButton("Non");
|
||||
buttons.add(yes);
|
||||
buttons.add(no);
|
||||
|
||||
yes.addActionListener(e -> { handler.onYes(); dispose(); });
|
||||
no.addActionListener(e -> { handler.onNo(); dispose(); });
|
||||
|
||||
content.add(msg, BorderLayout.CENTER);
|
||||
content.add(buttons, BorderLayout.SOUTH);
|
||||
setContentPane(content);
|
||||
pack();
|
||||
setLocationRelativeTo(parent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package galerie.view;
|
||||
|
||||
import galerie.model.ImageList;
|
||||
import galerie.control.HalfClickNavigator;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GalleryCardLayoutFrame extends JFrame {
|
||||
private final CardLayout cards = new CardLayout();
|
||||
private final JPanel deck = new JPanel(cards);
|
||||
|
||||
public GalleryCardLayoutFrame(ImageList images) {
|
||||
super("Galerie — CardLayout");
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setSize(800, 600);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
for (int i = 0; i < images.size(); i++) {
|
||||
JLabel lab = new JLabel(images.iconAt(i), SwingConstants.CENTER);
|
||||
lab.setVerticalAlignment(SwingConstants.CENTER);
|
||||
deck.add(lab, "card" + i);
|
||||
}
|
||||
deck.addMouseListener(new HalfClickNavigator(deck,
|
||||
() -> cards.next(deck),
|
||||
() -> cards.previous(deck)));
|
||||
|
||||
setContentPane(deck);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package galerie.view;
|
||||
|
||||
import galerie.model.ImageList;
|
||||
import galerie.control.HalfClickNavigator;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GalleryReplacementFrame extends JFrame {
|
||||
private final ImageList images;
|
||||
private final JLabel viewer = new JLabel("", SwingConstants.CENTER);
|
||||
|
||||
public GalleryReplacementFrame(ImageList images) {
|
||||
super("Galerie — Remplacement d'un seul JLabel");
|
||||
this.images = images;
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setSize(800, 600);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
viewer.setVerticalAlignment(SwingConstants.CENTER);
|
||||
viewer.setIcon(images.currentIcon());
|
||||
|
||||
JPanel surface = new JPanel(new BorderLayout());
|
||||
surface.add(viewer, BorderLayout.CENTER);
|
||||
surface.addMouseListener(new HalfClickNavigator(surface, this::next, this::previous));
|
||||
|
||||
setContentPane(surface);
|
||||
}
|
||||
|
||||
private void next() {
|
||||
images.next();
|
||||
viewer.setIcon(images.currentIcon());
|
||||
}
|
||||
|
||||
private void previous() {
|
||||
images.previous();
|
||||
viewer.setIcon(images.currentIcon());
|
||||
}
|
||||
}
|
||||