New implemented class PgnSelectionGui
parent
f3079dc82e
commit
2e6b9ec81c
|
@ -0,0 +1,39 @@
|
||||||
|
package de.hs_mannheim.informatik.chess.view;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
|
||||||
|
import com.github.bhlangonijr.chesslib.game.Game;
|
||||||
|
|
||||||
|
public class PgnSelectionGui extends JFrame {
|
||||||
|
public PgnSelectionGui(List<Game> games, Consumer<Game> onGameSelected) {
|
||||||
|
setTitle("Geladene Partien");
|
||||||
|
setSize(600, 800);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
JScrollPane scrollPane = new JScrollPane(panel);
|
||||||
|
|
||||||
|
int index = 1;
|
||||||
|
for (Game game : games) {
|
||||||
|
String white = game.getWhitePlayer().getName();
|
||||||
|
String black = game.getBlackPlayer().getName();
|
||||||
|
String title = "Spiel " + index++ + ": " + white + " vs. " + black;
|
||||||
|
JButton btn = new JButton(title);
|
||||||
|
btn.addActionListener(e -> {
|
||||||
|
dispose();
|
||||||
|
onGameSelected.accept(game);
|
||||||
|
});
|
||||||
|
panel.add(btn);
|
||||||
|
}
|
||||||
|
add(scrollPane);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue