diff --git a/DEV 3.1/Victoire/RefreshListener.class b/DEV 3.1/TP1/Victoire/RefreshListener.class similarity index 100% rename from DEV 3.1/Victoire/RefreshListener.class rename to DEV 3.1/TP1/Victoire/RefreshListener.class diff --git a/DEV 3.1/TP1/Victoire/RefreshListener.java b/DEV 3.1/TP1/Victoire/RefreshListener.java new file mode 100644 index 0000000..890f2ae --- /dev/null +++ b/DEV 3.1/TP1/Victoire/RefreshListener.java @@ -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(); + } +} diff --git a/DEV 3.1/TP1/Victoire/Victoire.class b/DEV 3.1/TP1/Victoire/Victoire.class new file mode 100644 index 0000000..3a7614c Binary files /dev/null and b/DEV 3.1/TP1/Victoire/Victoire.class differ diff --git a/DEV 3.1/Victoire/RefreshListener.java b/DEV 3.1/TP1/Victoire/Victoire.java similarity index 56% rename from DEV 3.1/Victoire/RefreshListener.java rename to DEV 3.1/TP1/Victoire/Victoire.java index 722071b..dff39d3 100644 --- a/DEV 3.1/Victoire/RefreshListener.java +++ b/DEV 3.1/TP1/Victoire/Victoire.java @@ -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(); } -} +} \ No newline at end of file diff --git a/DEV 3.1/TP1/Vote/Vote.class b/DEV 3.1/TP1/Vote/Vote.class new file mode 100644 index 0000000..d4ad17a Binary files /dev/null and b/DEV 3.1/TP1/Vote/Vote.class differ diff --git a/DEV 3.1/Vote/Vote.java b/DEV 3.1/TP1/Vote/Vote.java similarity index 77% rename from DEV 3.1/Vote/Vote.java rename to DEV 3.1/TP1/Vote/Vote.java index 11cade7..4c6910b 100644 --- a/DEV 3.1/Vote/Vote.java +++ b/DEV 3.1/TP1/Vote/Vote.java @@ -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; diff --git a/DEV 3.1/Victoire/Victoire.class b/DEV 3.1/Victoire/Victoire.class deleted file mode 100644 index 4ef2794..0000000 Binary files a/DEV 3.1/Victoire/Victoire.class and /dev/null differ diff --git a/DEV 3.1/Victoire/Victoire.java b/DEV 3.1/Victoire/Victoire.java deleted file mode 100644 index c95cff4..0000000 --- a/DEV 3.1/Victoire/Victoire.java +++ /dev/null @@ -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(); - } -} \ No newline at end of file diff --git a/DEV 3.1/Vote/Vote.class b/DEV 3.1/Vote/Vote.class deleted file mode 100644 index 8534ac6..0000000 Binary files a/DEV 3.1/Vote/Vote.class and /dev/null differ