diff --git a/src/main/java/de/tims/leaderboard/Leaderboard.java b/src/main/java/de/tims/leaderboard/Leaderboard.java index 54fe06a..8e0af3a 100644 --- a/src/main/java/de/tims/leaderboard/Leaderboard.java +++ b/src/main/java/de/tims/leaderboard/Leaderboard.java @@ -1,5 +1,7 @@ package de.tims.leaderboard; +import java.awt.Color; +import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -13,9 +15,11 @@ public class Leaderboard { private static final int NUM_PLAYERS_ON_LEADERBOARD = 10; private List allPlayers; + String actualPlayer; public Leaderboard(List allPlayers, String actualPlayer) { this.allPlayers = allPlayers; + this.actualPlayer = actualPlayer; } public Player[] getTop10Players() { @@ -51,40 +55,41 @@ public class Leaderboard { GridBagConstraints gbc = new GridBagConstraints(); - Player[] top10Players = getTop10Players(); - - gbc.gridx = 0; - gbc.gridy = 0; - gbc.weightx = 0.5; - gbc.weighty = 0.1; - gbc.anchor = GridBagConstraints.LINE_END; - gbc.insets = new Insets(5, 0, 5, 5); - mainPanel.add(new JLabel("Platzierung"), gbc); - - gbc.gridx = 1; - gbc.gridy = 0; - gbc.weightx = 0.0; - gbc.weighty = 0.1; - gbc.anchor = GridBagConstraints.LINE_START; - gbc.insets = new Insets(5, 5, 5, 10); - mainPanel.add(new JLabel("Name"), gbc); + JLabel place; + JLabel name; + JLabel points; - gbc.gridx = 2; - gbc.gridy = 0; - gbc.weightx = 0.5; - gbc.weighty = 0.1; - gbc.anchor = GridBagConstraints.LINE_START; - gbc.insets = new Insets(5, 10, 5, 0); - mainPanel.add(new JLabel("Punkte"), gbc); + Player[] top10Players = getTop10Players(); - for (int i = 0; i < top10Players.length; i++) { + for (int i = -1; i < top10Players.length; i++) { + if (i < 0) { + place = new JLabel("Platzierung"); + name = new JLabel("Name"); + points = new JLabel("Punkte"); + } else { + place = new JLabel((i + 1) + "."); + name = new JLabel(top10Players[i].getName()); + points = new JLabel("" + top10Players[i].getPoints()); + + if (top10Players[i].getName().equals(actualPlayer)) { + Font actualPlayerFont = new Font(Font.DIALOG, Font.PLAIN, 20); + + place.setForeground(Color.RED); + place.setFont(actualPlayerFont); + name.setForeground(Color.RED); + name.setFont(actualPlayerFont); + points.setForeground(Color.RED); + points.setFont(actualPlayerFont); + } + } + gbc.gridx = 0; gbc.gridy = i + 1; gbc.weightx = 0.5; gbc.weighty = 0.1; gbc.anchor = GridBagConstraints.LINE_END; gbc.insets = new Insets(5, 0, 5, 5); - mainPanel.add(new JLabel((i + 1) + "."), gbc); + mainPanel.add(place, gbc); gbc.gridx = 1; gbc.gridy = i + 1; @@ -92,7 +97,7 @@ public class Leaderboard { gbc.weighty = 0.1; gbc.anchor = GridBagConstraints.LINE_START; gbc.insets = new Insets(5, 5, 5, 10); - mainPanel.add(new JLabel(top10Players[i].getName()), gbc); + mainPanel.add(name, gbc); gbc.gridx = 2; gbc.gridy = i + 1; @@ -100,7 +105,7 @@ public class Leaderboard { gbc.weighty = 0.1; gbc.anchor = GridBagConstraints.LINE_START; gbc.insets = new Insets(5, 10, 5, 0); - mainPanel.add(new JLabel("" + top10Players[i].getPoints()), gbc); + mainPanel.add(points, gbc); } return mainPanel;