wow le tp là

This commit is contained in:
Simoes Lukas
2025-09-04 15:36:55 +02:00
parent c16ef0985f
commit 2c3e150ec5
87 changed files with 1059 additions and 28 deletions

Binary file not shown.

View File

@@ -0,0 +1,9 @@
public class Main {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Entrez une valeur dans la console.");
System.exit(0);
}
Vote v = new Vote(args[0]);
}
}

Binary file not shown.

View File

@@ -0,0 +1,52 @@
import org.mariadb.jdbc.*;
import java.awt.*;
import java.sql.*;
public class Vote {
private String competiteur;
public Vote(String competiteur) {
this.competiteur = competiteur;
try {
Connection cnx = DriverManager.getConnection(
"jdbc:mariadb://dwarves.iut-fbleau.fr/simoes",
"simoes", "simoes"
);
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch (ClassNotFoundException e2) {
System.err.println("Problème de pilote.");
}
try {
PreparedStatement pst = cnx.prepareStatement(
"SELECT votants, points FROM pays WHERE competiteur = '" + this.competiteur + "';"
);
ResultSet rs = pst.executeQuery();
int total = 0;
while (rs.next()) {
total += rs.getInt(2);
System.out.println(rs.getString(1) + " " + rs.getInt(2));
}
System.out.println("---------");
System.out.println("Total " + total);
rs.close();
pst.close();
} catch (SQLException e3) {
System.err.println("Erreur de syntaxe SQL.");
}
cnx.close();
} catch (SQLException e1) {
System.err.println("Erreur de connexion à la base de données.");
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,56 @@
import org.mariadb.jdbc.*;
import javax.swing.*;
import java.sql.*;
public class Connexion {
private int scoreMax;
private String paysMax;
public Connexion() {
try {
Connection cnx = DriverManager.getConnection(
"jdbc:mariadb://dwarves.iut-fbleau.fr/simoes",
"simoes", "simoes"
);
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch (ClassNotFoundException e2) {
System.err.println("Problème de pilote.");
}
try {
PreparedStatement pst = cnx.prepareStatement(
"SELECT SUM(points), competiteur FROM pays GROUP BY competiteur ASC;"
);
ResultSet rs = pst.executeQuery();
int total = 0;
rs.next();
this.scoreMax = rs.getInt(1);
this.paysMax = rs.getString(2);
rs.close();
pst.close();
} catch (SQLException e3) {
System.err.println("Erreur de syntaxe SQL.");
}
cnx.close();
} catch (SQLException e1) {
System.err.println("Erreur de connexion à la base de données.");
}
}
public String getNomPays() {
return this.paysMax;
}
public int getScorePays() {
return this.scoreMax;
}
}

Binary file not shown.

View File

@@ -0,0 +1,43 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
private String nomPays;
private int scorePays;
public Fenetre(String nomPays, int scorePays) {
this.nomPays = nomPays;
this.scorePays = scorePays;
this.setSize(200, 200);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
JLabel pays = new JLabel(this.nomPays);
JLabel score = new JLabel(this.scorePays + "");
JPanel south = new JPanel();
JButton refresh = new JButton("");
refresh.addActionListener(new Rafraichir(score, pays, this));
Font policeScore = new Font("Arial", Font.BOLD, 60);
Font policePays = new Font("Arial", Font.BOLD, 40);
score.setFont(policeScore);
pays.setFont(policePays);
pays.setHorizontalAlignment(JLabel.CENTER);
score.setHorizontalAlignment(JLabel.CENTER);
refresh.setHorizontalAlignment(JButton.RIGHT);
this.add(pays, BorderLayout.NORTH);
this.add(score, BorderLayout.CENTER);
this.add(south, BorderLayout.SOUTH);
south.setLayout(new BorderLayout());
south.add(refresh, BorderLayout.EAST);
}
}

Binary file not shown.

View File

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

Binary file not shown.

View File

@@ -0,0 +1,25 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Rafraichir implements ActionListener {
private JLabel texteScore;
private JLabel textePays;
private Fenetre fenetre;
public Rafraichir(JLabel texteScore, JLabel textePays, Fenetre fenetre) {
this.texteScore = texteScore;
this.textePays = textePays;
this.fenetre = fenetre;
}
public void actionPerformed(ActionEvent evenement) {
Connexion cnx2 = new Connexion();
this.texteScore.setText(cnx2.getScorePays() + "");
this.textePays.setText(cnx2.getNomPays());
this.fenetre.repaint();
}
}

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,18 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(900, 450);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_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));
}
}

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

Binary file not shown.

View File

@@ -0,0 +1,35 @@
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 int actuel;
private CardLayout layout;
public Controlleur(JLabel[] img, Fenetre fenetre, CardLayout layout) {
this.img = img;
this.fenetre = fenetre;
this.actuel = 0;
this.layout = layout;
}
public void mouseClicked(MouseEvent evenement) {
if (evenement.getX() < this.fenetre.getWidth()/2) {
this.layout.previous(this.fenetre.getContentPane());
}
else {
this.layout.next(this.fenetre.getContentPane());
}
this.layout.show(this.fenetre.getContentPane(), "wow");
} // 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,27 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(900, 450);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CardLayout layout = new CardLayout();
this.setLayout(layout);
JLabel img1 = new JLabel(new ImageIcon("img1.jpg"));
JLabel img2 = new JLabel(new ImageIcon("img2.jpg"));
JLabel img3 = new JLabel(new ImageIcon("img3.jpg"));
JLabel img4 = new JLabel(new ImageIcon("img4.jpg"));
JLabel[] tableau = {img1, img2, img3, img4};
this.add(img1);
this.add(img2);
this.add(img3);
this.add(img4);
this.addMouseListener(new Controlleur(tableau, this, layout));
}
}

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

Binary file not shown.

View File

@@ -0,0 +1,64 @@
import java.awt.*;
import javax.swing.*;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(300, 200);
this.setLocation(100, 100);
GridBagLayout layout = new GridBagLayout();
this.setLayout(layout);
GridBagConstraints gbc = new GridBagConstraints();
JButton b1 = new JButton("1");
JButton b2 = new JButton("2");
JButton b3 = new JButton("3");
JButton b4 = new JButton("4");
JButton b5 = new JButton("5");
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.gridheight = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
this.add(b1, gbc);
gbc.gridx = 2;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 2;
this.add(b2, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
gbc.gridwidth = 2;
gbc.gridheight = 1;
this.add(b3, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 2;
this.add(b4, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
this.add(b5, gbc);
this.addWindowListener(new WindowControler(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.

View File

@@ -0,0 +1,50 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
public class WindowControler implements WindowListener {
private Fenetre fenetre;
public WindowControler(Fenetre fenetre) {
this.fenetre = fenetre;
}
public void windowActivated(WindowEvent evenement) {
}
public void windowClosed(WindowEvent evenement) {
}
public void windowClosing(WindowEvent evenement) {
int resultat = JOptionPane.showConfirmDialog(fenetre, null);
if (resultat == JOptionPane.YES_OPTION) {
fenetre.dispose();
}
} // avant fermeture
public void windowDeactivated(WindowEvent evenement) {
}
public void windowDeiconified(WindowEvent evenement) {
}
public void windowIconified(WindowEvent evenement) {
}
public void windowOpened(WindowEvent evenement) {
}
}