wow le tp là
This commit is contained in:
BIN
DEV3.1/TP01/01_Vote/Main.class
Normal file
BIN
DEV3.1/TP01/01_Vote/Main.class
Normal file
Binary file not shown.
9
DEV3.1/TP01/01_Vote/Main.java
Normal file
9
DEV3.1/TP01/01_Vote/Main.java
Normal 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]);
|
||||
}
|
||||
}
|
BIN
DEV3.1/TP01/01_Vote/Vote.class
Normal file
BIN
DEV3.1/TP01/01_Vote/Vote.class
Normal file
Binary file not shown.
52
DEV3.1/TP01/01_Vote/Vote.java
Normal file
52
DEV3.1/TP01/01_Vote/Vote.java
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV3.1/TP01/02_Victoire/Connexion.class
Normal file
BIN
DEV3.1/TP01/02_Victoire/Connexion.class
Normal file
Binary file not shown.
56
DEV3.1/TP01/02_Victoire/Connexion.java
Normal file
56
DEV3.1/TP01/02_Victoire/Connexion.java
Normal 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;
|
||||
}
|
||||
}
|
BIN
DEV3.1/TP01/02_Victoire/Fenetre.class
Normal file
BIN
DEV3.1/TP01/02_Victoire/Fenetre.class
Normal file
Binary file not shown.
43
DEV3.1/TP01/02_Victoire/Fenetre.java
Normal file
43
DEV3.1/TP01/02_Victoire/Fenetre.java
Normal 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);
|
||||
|
||||
}
|
||||
}
|
BIN
DEV3.1/TP01/02_Victoire/Main.class
Normal file
BIN
DEV3.1/TP01/02_Victoire/Main.class
Normal file
Binary file not shown.
7
DEV3.1/TP01/02_Victoire/Main.java
Normal file
7
DEV3.1/TP01/02_Victoire/Main.java
Normal 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);
|
||||
}
|
||||
}
|
BIN
DEV3.1/TP01/02_Victoire/Rafraichir.class
Normal file
BIN
DEV3.1/TP01/02_Victoire/Rafraichir.class
Normal file
Binary file not shown.
25
DEV3.1/TP01/02_Victoire/Rafraichir.java
Normal file
25
DEV3.1/TP01/02_Victoire/Rafraichir.java
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user