TP1 Termi,né

This commit is contained in:
HORVILLE 2022-09-07 15:35:41 +02:00
parent 6b8527e3c8
commit 5495b60332
9 changed files with 61 additions and 44 deletions

View File

@ -0,0 +1,14 @@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class RefreshListener implements ActionListener {
public RefreshListener() {
}
public void actionPerformed(ActionEvent e) {
Victoire.refresh();
}
}

Binary file not shown.

View File

@ -1,10 +1,13 @@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
public class RefreshListener implements ActionListener {
public RefreshListener() {
public class Victoire {
public static JLabel scoreLabel;
public static JLabel countryLabel;
public static void refresh() {
try {
Class.forName("org.mariadb.jdbc.Driver");
} catch (ClassNotFoundException ex) {
@ -21,11 +24,11 @@ public class RefreshListener implements ActionListener {
}
try {
PreparedStatement req = cnx.prepareStatement("SELECT Competiteur, SUM(Points) FROM Vote GROUP BY Competiteur;");
PreparedStatement req = cnx.prepareStatement("SELECT Nom, SUM(Points) FROM Vote LEFT JOIN Pays ON Vote.Competiteur = Pays.ID GROUP BY Nom;");
req.executeUpdate();
int maxPoints = 0;
String country;
String country = "";
ResultSet rs = req.executeQuery();
while (rs.next()) {
int score = rs.getInt(2);
@ -35,6 +38,14 @@ public class RefreshListener implements ActionListener {
}
}
if (country != "") {
countryLabel.setText(country);
scoreLabel.setText(Integer.toString(maxPoints));
}
rs.close();
req.close();
@ -50,7 +61,23 @@ public class RefreshListener implements ActionListener {
}
}
public void actionPerformed(ActionEvent e) {
public static void main(String[] args) {
JFrame window = new JFrame("Victoire");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(300, 300);
window.setLocation(200, 200);
JButton refreshBT = new JButton("");
refreshBT.addActionListener(new RefreshListener());
window.add(refreshBT, BorderLayout.SOUTH);
window.setVisible(true);
countryLabel = new JLabel("...", JLabel.CENTER);
scoreLabel = new JLabel("0", JLabel.CENTER);
window.add(countryLabel, BorderLayout.NORTH);
window.add(scoreLabel, BorderLayout.CENTER);
Victoire.refresh();
}
}
}

BIN
DEV 3.1/TP1/Vote/Vote.class Normal file

Binary file not shown.

View File

@ -23,8 +23,17 @@ public class Vote {
}
try {
PreparedStatement req = cnx.prepareStatement("SELECT Votants, Points FROM Vote WHERE Competiteur = (?);");
req.setString(1, args[0]);
PreparedStatement nameReq = cnx.prepareStatement("SELECT ID FROM Pays WHERE Nom = (?);");
nameReq.setString(1, args[0]);
nameReq.executeUpdate();
ResultSet rs1 = nameReq.executeQuery();
rs1.next();
String nom = rs1.getString(1);
rs1.close();
PreparedStatement req = cnx.prepareStatement("SELECT Nom, Points FROM Vote LEFT JOIN Pays ON Vote.Votants = Pays.ID WHERE Competiteur = (?);");
req.setString(1, nom);
req.executeUpdate();
int total = 0;

Binary file not shown.

View File

@ -1,33 +0,0 @@
import java.sql.*;
import javax.swing.*;
import java.awt.*;
public class Victoire {
public static JLabel scoreLabel;
public static JLabel countryLabel;
public static void refresh() {
}
public static void main(String[] args) {
JFrame window = new JFrame("Victoire");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(300, 300);
window.setLocation(200, 200);
JButton refreshBT = new JButton("");
refreshBT.addActionListener(new RefreshListener());
window.add(refreshBT, BorderLayout.SOUTH);
window.setVisible(true);
countryLabel = new JLabel("...", JLabel.CENTER);
scoreLabel = new JLabel("0", JLabel.CENTER);
window.add(countryLabel, BorderLayout.NORTH);
window.add(scoreLabel, BorderLayout.CENTER);
Victoire.refresh();
}
}

Binary file not shown.