Browse Source

leaderboard: added gui layout

leaderboard
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
981b31dd99
  1. 54
      src/main/java/de/tims/leaderboard/Leaderboard.java
  2. 2
      src/main/java/de/tims/leaderboard/LeaderboardGUITest.java

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

@ -1,5 +1,8 @@
package de.tims.leaderboard;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;
import javax.swing.*;
@ -44,11 +47,60 @@ public class Leaderboard {
public JPanel buildLeaderboard() {
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new GridBagLayout());
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);
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);
for (int i = 0; i < top10Players.length; i++) {
mainPanel.add(new JLabel(i + 1 + ". " + top10Players[i].getName() + " " + top10Players[i].getPoints()));
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);
gbc.gridx = 1;
gbc.gridy = i + 1;
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(top10Players[i].getName()), gbc);
gbc.gridx = 2;
gbc.gridy = i + 1;
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("" + top10Players[i].getPoints()), gbc);
}
return mainPanel;

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

@ -21,7 +21,7 @@ public class LeaderboardGUITest {
panel = leaderboard.buildLeaderboard();
frame.add(panel);
frame.setSize(240, 240);
frame.setSize(640, 400);
frame.setVisible(true);
}

Loading…
Cancel
Save