-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStatspage.java
More file actions
88 lines (73 loc) · 2.97 KB
/
Copy pathStatspage.java
File metadata and controls
88 lines (73 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class Statspage extends JFrame {
public Statspage() {
setTitle("IPL 2026 - Stats Dashboard");
setSize(1000, 700);
setLocationRelativeTo(null);
setLayout(new BorderLayout());
JPanel header = new JPanel();
header.setBackground(new Color(25, 25, 112));
JLabel title = new JLabel("IPL 2026 POINTS TABLE");
title.setFont(new Font("Arial", Font.BOLD, 28));
title.setForeground(Color.WHITE);
header.add(title);
add(header, BorderLayout.NORTH);
// 1. Removed "NRR" from the columns array
String[] columns = {"Rank", "Team", "Played", "Won", "Lost", "Points"};
DefaultTableModel model = new DefaultTableModel(columns, 0) {
@Override
public boolean isCellEditable(int r, int c) {
return false;
}
};
JTable table = new JTable(model);
table.setRowHeight(35);
table.getTableHeader().setFont(new Font("Arial", Font.BOLD, 16));
loadPoints(model);
add(new JScrollPane(table), BorderLayout.CENTER);
JButton backBtn = new JButton("← Back to Schedule");
backBtn.setFont(new Font("Arial", Font.BOLD, 16));
backBtn.addActionListener(e -> {
new Homepage().setVisible(true);
dispose();
});
JButton refreshBtn = new JButton("Refresh");
refreshBtn.setFont(new Font("Arial", Font.BOLD, 16));
refreshBtn.addActionListener(e -> loadPoints(model));
JPanel buttonPanel = new JPanel();
buttonPanel.add(backBtn);
buttonPanel.add(refreshBtn);
add(buttonPanel, BorderLayout.SOUTH);
}
private void loadPoints(DefaultTableModel model) {
model.setRowCount(0);
// Query to load points table data
String query = "SELECT t.team_name, p.played, p.won, p.lost, p.points "
+ "FROM points_table p "
+ "JOIN teams t ON p.team_id = t.team_id "
+ "ORDER BY p.points DESC";
try (Connection con = DBConnection.getConnection(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery(query)) {
int rank = 1;
int count = 0;
while (rs.next()) {
count++;
model.addRow(new Object[]{
rank++,
rs.getString("team_name"),
rs.getInt("played"),
rs.getInt("won"),
rs.getInt("lost"),
rs.getInt("points")
});
}
if (count == 0) {
JOptionPane.showMessageDialog(this, "No teams found in points table. Add teams first and play matches to see points.");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error loading points: " + e.getMessage());
}
}
}