Files
SAE31_2024/src/fr/monkhanny/dorfromantik/gui/LeaderboardByTier.java

65 lines
2.3 KiB
Java

package fr.monkhanny.dorfromantik.gui;
import javax.swing.*;
import java.awt.*;
// @TODO : MODIFIER CAR C'EST PAS BEAU + BDD
public class LeaderboardByTier extends Leaderboard {
public LeaderboardByTier() {
super();
refresh(); // Charge les données initiales
}
@Override
public void refresh() {
removeAll(); // Supprime tout contenu existant
setBackground(new Color(64, 0, 128));
// Titre
JLabel titleLabel = new JLabel("CLASSEMENT PAR TRANCHE");
titleLabel.setForeground(Color.WHITE);
titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
add(titleLabel, BorderLayout.NORTH);
// Contenu
JPanel tierPanel = new JPanel();
tierPanel.setLayout(new BoxLayout(tierPanel, BoxLayout.Y_AXIS));
tierPanel.setBackground(new Color(64, 0, 128));
// Exemple de tranche
int totalPlayers = 1000;
int rank = 237; // Exemple : rang du joueur
int tierSize = totalPlayers / 10;
int tier = (rank - 1) / tierSize + 1;
// Label indiquant la tranche dans laquelle le joueur se trouve
JLabel infoLabel = new JLabel("Vous êtes dans la tranche : " + tier);
infoLabel.setFont(new Font("Arial", Font.PLAIN, 18));
infoLabel.setForeground(Color.WHITE);
infoLabel.setAlignmentX(CENTER_ALIGNMENT);
// Pourcentage du joueur
double percentage = (double) rank / totalPlayers * 100;
JLabel percentageLabel = new JLabel(String.format("Vous faites partie des %.2f%% des joueurs", percentage));
percentageLabel.setFont(new Font("Arial", Font.PLAIN, 18));
percentageLabel.setForeground(Color.WHITE);
percentageLabel.setAlignmentX(CENTER_ALIGNMENT);
// Ajouter les labels à la JPanel
tierPanel.add(Box.createVerticalStrut(20));
tierPanel.add(infoLabel);
tierPanel.add(percentageLabel);
// Ajouter le diagramme en barres pour les tranches
LeaderboardBarChartPanel barChartPanel = new LeaderboardBarChartPanel(totalPlayers, rank);
tierPanel.add(Box.createVerticalStrut(20)); // Espacement
tierPanel.add(barChartPanel);
add(tierPanel, BorderLayout.CENTER);
revalidate();
repaint();
}
}