Browse Source

leaderboard: added method buildLeaderboard

leaderboard
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
2cc2b6333d
  1. 13
      src/main/java/de/tims/leaderboard/Leaderboard.java
  2. 32
      src/main/java/de/tims/leaderboard/LeaderboardGUITest.java

13
src/main/java/de/tims/leaderboard/Leaderboard.java

@ -1,6 +1,7 @@
package de.tims.leaderboard; package de.tims.leaderboard;
import java.util.List; import java.util.List;
import javax.swing.*;
import de.tims.player_management.Player; import de.tims.player_management.Player;
@ -40,5 +41,17 @@ public class Leaderboard {
return top10Players; return top10Players;
} }
public JPanel buildLeaderboard() {
JPanel mainPanel = new JPanel();
Player[] top10Players = getTop10Players();
for (int i = 0; i < top10Players.length; i++) {
mainPanel.add(new JLabel(i + 1 + ". " + top10Players[i].getName() + " " + top10Players[i].getPoints()));
}
return mainPanel;
}
} }

32
src/main/java/de/tims/leaderboard/LeaderboardGUITest.java

@ -0,0 +1,32 @@
package de.tims.leaderboard;
import java.util.List;
import javax.swing.*;
import de.tims.player_management.Player;
public class LeaderboardGUITest {
private JFrame frame;
private JPanel panel;
Leaderboard leaderboard;
public LeaderboardGUITest() {
frame = new JFrame("LeaderboardGUITest");
leaderboard = new Leaderboard(List.of(new Player("Eins", 0), new Player("Zwei", 130), new Player("Drei", 20), new Player("Vier", 10),
new Player("Fuenf", 20), new Player("Sechs", 70), new Player("Sieben", 60), new Player("Acht", 20),
new Player("Neun", 60), new Player("Zehn", 50), new Player("Elf", 90), new Player("Zwoelf", 20),
new Player("Dreizehn", 40), new Player("Vierzehn", 80)), "Neun");
panel = leaderboard.buildLeaderboard();
frame.add(panel);
frame.setSize(240, 240);
frame.setVisible(true);
}
public static void main(String[] args) {
new LeaderboardGUITest();
}
}
Loading…
Cancel
Save