package linea; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.*; public class MenuLeaderboard extends JPanel { private JTable leaderboardTable; private final Jeu jeu; public MenuLeaderboard(Jeu jeu) { this.jeu = jeu; setLayout(new BorderLayout(10, 10)); setBackground(new Color(45, 45, 45)); JLabel titre = new JLabel("LEADERBOARD", SwingConstants.CENTER); titre.setForeground(Color.WHITE); titre.setFont(new Font("SansSerif", Font.BOLD, 40)); add(titre, BorderLayout.NORTH); // Configuration du tableau leaderboardTable = new JTable(); leaderboardTable.setFont(new Font("SansSerif", Font.PLAIN, 16)); leaderboardTable.setRowHeight(25); leaderboardTable.setBackground(new Color(60, 60, 60)); leaderboardTable.setForeground(Color.WHITE); leaderboardTable.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 18)); leaderboardTable.getTableHeader().setBackground(new Color(30, 30, 30)); leaderboardTable.getTableHeader().setForeground(Color.WHITE); JScrollPane scrollPane = new JScrollPane(leaderboardTable); scrollPane.getViewport().setBackground(new Color(45, 45, 45)); scrollPane.setBorder(BorderFactory.createEmptyBorder(20, 50, 20, 50)); add(scrollPane, BorderLayout.CENTER); // Bouton de retour JButton btnRetour = new JButton("Retour"); btnRetour.setFont(new Font("SansSerif", Font.PLAIN, 18)); btnRetour.addActionListener(e -> jeu.afficherMenuPrincipal()); JPanel southPanel = new JPanel(); southPanel.setBackground(new Color(45, 45, 45)); southPanel.add(btnRetour); add(southPanel, BorderLayout.SOUTH); } public void rafraichirLeaderboard() { Object[][] data = jeu.bdd.getLeaderboardData(); String[] columnNames = {"Identifiant", "Score", "Date"}; // Utilisation d'un DefaultTableModel pour rendre les cellules non éditables leaderboardTable.setModel(new DefaultTableModel(data, columnNames) { @Override public boolean isCellEditable(int row, int column) { return false; } }); } }