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());
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
TP_DEV3.2/Genericite/Exo1.class
Normal file
69
TP_DEV3.2/Genericite/Exo1.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import java.util.*; // pour ArrayList, List, Arrays, Comparator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class Exo1 {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main (String[] args) {
|
||||||
|
|
||||||
|
List<Integer> liste1 = new ArrayList<>();
|
||||||
|
liste1.add(9);
|
||||||
|
liste1.add(1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
List<Number> liste2 = new ArrayList<>();
|
||||||
|
liste2.add(15);
|
||||||
|
liste2.add(1.5f);
|
||||||
|
liste2.add(15000L);
|
||||||
|
|
||||||
|
|
||||||
|
List<Float> liste3 = new ArrayList<>();
|
||||||
|
liste3.add(3.93f);
|
||||||
|
liste3.add(3.07f);
|
||||||
|
|
||||||
|
System.out.println("liste 1 (Integer) ="+ liste1);
|
||||||
|
System.out.println("liste 2 (Number) ="+ liste2);
|
||||||
|
System.out.println("liste 3 (Float) ="+ liste3);
|
||||||
|
|
||||||
|
|
||||||
|
liste2.addAll(liste1);
|
||||||
|
liste2.addAll(liste3);
|
||||||
|
|
||||||
|
System.out.println("Apres versement des liste 1 et 3 dans la 2" + liste2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BIN
TP_DEV3.2/Genericite/Exodeux.class
Normal file
83
TP_DEV3.2/Genericite/Exodeux.java
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import java.util.*; // pour ArrayList, List, Arrays, Comparator
|
||||||
|
|
||||||
|
public class Exodeux {
|
||||||
|
|
||||||
|
|
||||||
|
public static void main (String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AfficherTouslesArgs(args);
|
||||||
|
AfficherLes5erArgs(args);
|
||||||
|
trierEtAfficherNaturel(args);
|
||||||
|
trierEtAffiicherSansCasse(args);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void AfficherTouslesArgs(String[] arguments){
|
||||||
|
|
||||||
|
|
||||||
|
String TousLesArgsTransforme = Arrays.toString(arguments);
|
||||||
|
System.out.println("Voici tous les args " + TousLesArgsTransforme);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AfficherLes5erArgs(String[] arguments) {
|
||||||
|
|
||||||
|
int limite = Math.min(5, arguments.length);
|
||||||
|
String[] premier = Arrays.copyOf(arguments,limite);
|
||||||
|
System.out.println("Voici les 5er arguments : "+Arrays.toString(premier));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void trierEtAfficherNaturel(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
String[] copyArgument = Arrays.copyOf(args, args.length);
|
||||||
|
|
||||||
|
Arrays.sort(copyArgument);
|
||||||
|
|
||||||
|
String NaturelTriage = Arrays.toString(copyArgument);
|
||||||
|
|
||||||
|
System.out.println("Tri naturel" + NaturelTriage);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void trierEtAffiicherSansCasse(String[] args){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String[] copyArgument = Arrays.copyOf(args, args.length);
|
||||||
|
Arrays.sort(copyArgument,String::compareToIgnoreCase);
|
||||||
|
String SansCasseTrierNickelChrome = Arrays.toString(copyArgument);
|
||||||
|
System.out.println("Tri sans casse naturel : "+ SansCasseTrierNickelChrome);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
106
TP_DEV3.2/Genericite/Exotrois.java
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
public class Exotrois {
|
||||||
|
|
||||||
|
|
||||||
|
public static <T> plusFrequent(T[] tableau){
|
||||||
|
|
||||||
|
|
||||||
|
T valeurGagnante = tableau[0];
|
||||||
|
int frequenceGagnante = 0;
|
||||||
|
int premierIndexGagnant = tableau.length;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for(int i=0;i<tableau.length; i++){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
T valeurCourante = tableau[i];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int frequenceCourante =0;
|
||||||
|
for(int k=0; k<tableau.length; k++){
|
||||||
|
|
||||||
|
if(Object.equals(tableau[k], valeurCourante)){
|
||||||
|
|
||||||
|
frequenceCourante++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
int premierIndexCourant = -1;
|
||||||
|
for(int j=0; j<tableau.length; j++){
|
||||||
|
|
||||||
|
if(Object.equals(tableau[j]), valeurCourante){
|
||||||
|
|
||||||
|
premierIndexCourant=j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
BIN
TP_DEV3.2/Liste/Luminance.class
Normal file
107
TP_DEV3.2/Liste/Luminance.java
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Luminance extends JPanel implements MouseListener {
|
||||||
|
|
||||||
|
private final Random random = new Random();
|
||||||
|
private final List<Color> couleurs = new LinkedList<>();
|
||||||
|
|
||||||
|
private static final int NB_COULEURS = 10;
|
||||||
|
private static final int LARGEUR = 60;
|
||||||
|
private static final int HAUTEUR = 80;
|
||||||
|
private static final int ESPACE = 8;
|
||||||
|
private static final int INCLINAISON = 15; // décalage pour le parallélogramme
|
||||||
|
|
||||||
|
public Luminance() {
|
||||||
|
for (int i = 0; i < NB_COULEURS; i++) {
|
||||||
|
int r = random.nextInt(256);
|
||||||
|
int g = random.nextInt(256);
|
||||||
|
int b = random.nextInt(256);
|
||||||
|
couleurs.add(new Color(r, g, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
int largeurFenetre = (LARGEUR + ESPACE) * NB_COULEURS + 40;
|
||||||
|
int hauteurFenetre = HAUTEUR + 60;
|
||||||
|
this.setPreferredSize(new Dimension(largeurFenetre, hauteurFenetre));
|
||||||
|
addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int LuminenceApp(Color c) {
|
||||||
|
int rouge = c.getRed();
|
||||||
|
int vert = c.getGreen();
|
||||||
|
int bleu = c.getBlue();
|
||||||
|
return (21 * rouge + 72 * vert + 7 * bleu) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics pinceau) {
|
||||||
|
super.paintComponent(pinceau);
|
||||||
|
Graphics g = pinceau;
|
||||||
|
|
||||||
|
int x = 20;
|
||||||
|
int y = 20;
|
||||||
|
|
||||||
|
for (Color c : couleurs) {
|
||||||
|
g.setColor(c);
|
||||||
|
|
||||||
|
// dessin d’un parallélogramme
|
||||||
|
int[] xs = {x + INCLINAISON, x + LARGEUR + INCLINAISON, x + LARGEUR, x};
|
||||||
|
int[] ys = {y, y, y + HAUTEUR, y + HAUTEUR};
|
||||||
|
Polygon p = new Polygon(xs, ys, 4);
|
||||||
|
|
||||||
|
g.fillPolygon(p);
|
||||||
|
g.setColor(Color.DARK_GRAY);
|
||||||
|
g.drawPolygon(p);
|
||||||
|
|
||||||
|
x = x + LARGEUR + ESPACE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int indexAt(int mx, int my) {
|
||||||
|
int x = 20;
|
||||||
|
int y = 20;
|
||||||
|
|
||||||
|
for (int i = 0; i < couleurs.size(); i++) {
|
||||||
|
int[] xs = {x + INCLINAISON, x + LARGEUR + INCLINAISON, x + LARGEUR, x};
|
||||||
|
int[] ys = {y, y, y + HAUTEUR, y + HAUTEUR};
|
||||||
|
Polygon p = new Polygon(xs, ys, 4);
|
||||||
|
|
||||||
|
if (p.contains(mx, my)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = x + LARGEUR + ESPACE;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
int intervalle = indexAt(e.getX(), e.getY());
|
||||||
|
if (intervalle >= 0) {
|
||||||
|
Color c = couleurs.get(intervalle);
|
||||||
|
System.out.println("Luminance = " + LuminenceApp(c) +
|
||||||
|
" (R = " + c.getRed() + " G = " + c.getGreen() + " B = " + c.getBlue() + ")");
|
||||||
|
couleurs.remove(intervalle);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void mousePressed(MouseEvent e) {}
|
||||||
|
@Override public void mouseReleased(MouseEvent e) {}
|
||||||
|
@Override public void mouseEntered(MouseEvent e) {}
|
||||||
|
@Override public void mouseExited(MouseEvent e) {}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame f = new JFrame("Luminence");
|
||||||
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
f.setContentPane(new Luminance());
|
||||||
|
f.pack();
|
||||||
|
f.setLocationRelativeTo(null);
|
||||||
|
f.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
33
TP_DEV3.2/Liste/Maillon.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class ChainedList<E> implements List<E>{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static class Node<E>{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
E value;
|
||||||
|
Node<E> next;
|
||||||
|
Node(E v){
|
||||||
|
|
||||||
|
value = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
51
TP_DEV3.2/Piles/Arithmetique.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
|
public class Arithmetique {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// Exemple : 18 6 1 2 + 9 + / + 8 7 - *
|
||||||
|
// String[] args = {"18", "6", "1", "2", "+", "9", "+", "/", "+", "8", "7", "-", "*"};
|
||||||
|
|
||||||
|
Stack<Integer> pile = new Stack<>();
|
||||||
|
|
||||||
|
for (String element : args) {
|
||||||
|
if (estNombre(element)) {
|
||||||
|
// Si c’est un nombre, on le met dans la pile
|
||||||
|
pile.push(Integer.parseInt(element));
|
||||||
|
} else {
|
||||||
|
// Sinon c’est un opérateur on dépile 2 valeurs
|
||||||
|
int b = pile.pop();
|
||||||
|
int a = pile.pop();
|
||||||
|
int resultat = calculer(a, b, element);
|
||||||
|
// On empile le résultat
|
||||||
|
pile.push(resultat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// À la fin, il reste le résultat final dans la pile
|
||||||
|
System.out.println("Résultat = " + pile.pop());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifie si une chaîne est un nombre
|
||||||
|
public static boolean estNombre(String s) {
|
||||||
|
try {
|
||||||
|
Integer.parseInt(s);
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcule a (op) b
|
||||||
|
public static int calculer(int a, int b, String op) {
|
||||||
|
switch (op) {
|
||||||
|
case "+": return a + b;
|
||||||
|
case "-": return a - b;
|
||||||
|
case "*": return a * b;
|
||||||
|
case "/": return a / b;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Opérateur inconnu : " + op);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
TP_DEV3.2/Piles/Pile.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
public class Pile {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
BIN
TP_DEV3.2/Recursivité/Appels.class
Normal file
48
TP_DEV3.2/Recursivité/Appels.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import java.io.*;
|
||||||
|
import java.lang.Thread;
|
||||||
|
|
||||||
|
public class Appels {
|
||||||
|
|
||||||
|
|
||||||
|
public static int Factorielle (int n){
|
||||||
|
|
||||||
|
Thread.dumpStack();
|
||||||
|
|
||||||
|
if(n==0){
|
||||||
|
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
return n*Factorielle(n-1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*System.out.println()
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(args.length != 1){
|
||||||
|
|
||||||
|
System.out.println("Usage : java Appel <entier>");
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int n = Integer.parseInt(args[0]);
|
||||||
|
|
||||||
|
int resultat = Factorielle(n);
|
||||||
|
|
||||||
|
System.out.println(n+"! = " + resultat);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
19
TP_DEV3.2/Recursivité/Fibonacci.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
public class Fibonacci {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public int Fibonacci (int a){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
BIN
TP_DEV3.2/Recursivité/Tableaux.class
Normal file
82
TP_DEV3.2/Recursivité/Tableaux.java
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
public class Tableaux{
|
||||||
|
|
||||||
|
public static void remplir(String[] args, int[] tab, int i) {
|
||||||
|
// Cas de base
|
||||||
|
if (i == args.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cas récursif
|
||||||
|
tab[i] = Integer.parseInt(args[i]);
|
||||||
|
remplir(args, tab, i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void AfficheTableaux(int[] tab, int i){
|
||||||
|
|
||||||
|
if(i==tab.length){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(tab[i]);
|
||||||
|
AfficheTableaux(tab,i+1);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void AfficheTableauxInverse(int[] tab, int i){
|
||||||
|
if(i<0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(tab[i]);
|
||||||
|
AfficheTableauxInverse(tab, i-1);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int MaxTab(int[] tab, int i){
|
||||||
|
|
||||||
|
if(i==tab.length-1){
|
||||||
|
|
||||||
|
|
||||||
|
return tab[i];
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int maxRestant=MaxTab(tab,i+1);
|
||||||
|
return Math.max(tab[i], maxRestant);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public static void main(String[] args){
|
||||||
|
|
||||||
|
|
||||||
|
if(args.length <1){
|
||||||
|
|
||||||
|
System.out.println("Usage : java Tableaux <entier>");
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
int[] tab = new int[args.length];
|
||||||
|
remplir(args,tab,0);
|
||||||
|
AfficheTableaux(tab, 0);
|
||||||
|
AfficheTableauxInverse(tab,tab.length-1);
|
||||||
|
int max = MaxTab(tab,0);
|
||||||
|
System.out.println("Le maximum est :"+ max);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
46
TP_SCR/TP_Fichiers/cp_stdio_ultra.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include <stdio.h> // pour printf, fprintf, fopen, fread, fwrite, fclose
|
||||||
|
#include <stdlib.h> // pour exit()
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
FILE *source, *dest; // pointeurs de fichiers
|
||||||
|
char c; // variable pour stocker un octet lu
|
||||||
|
|
||||||
|
// Vérifier que l'utilisateur a bien fourni deux arguments (source et destination)
|
||||||
|
if (argc != 3) {
|
||||||
|
fprintf(stderr, "Usage: %s <fichier_source> <fichier_dest>\n", argv[0]);
|
||||||
|
exit(1); // quitte le programme avec code d'erreur
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ouvrir le fichier source en mode lecture binaire ("rb")
|
||||||
|
source = fopen(argv[1], "rb");
|
||||||
|
if (source == NULL) { // si l'ouverture échoue
|
||||||
|
perror("Erreur ouverture source");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ouvrir ou créer le fichier destination en mode écriture binaire ("wb")
|
||||||
|
dest = fopen(argv[2], "wb");
|
||||||
|
if (dest == NULL) { // si l'ouverture échoue
|
||||||
|
perror("Erreur ouverture destination");
|
||||||
|
fclose(source); // on ferme le fichier source déjà ouvert
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lire un octet depuis le fichier source puis l'écrire dans le fichier destination
|
||||||
|
while (fread(&c, 1, 1, source) == 1) {
|
||||||
|
if (fwrite(&c, 1, 1, dest) != 1) {
|
||||||
|
perror("Erreur écriture");
|
||||||
|
fclose(source);
|
||||||
|
fclose(dest);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fermer les deux fichiers
|
||||||
|
fclose(source);
|
||||||
|
fclose(dest);
|
||||||
|
|
||||||
|
// Indiquer que la copie s'est terminée correctement
|
||||||
|
printf("Copie terminée (méthode stdio).\n");
|
||||||
|
return 0; // programme terminé sans erreur
|
||||||
|
}
|
||||||