60 lines
1.8 KiB
Java
60 lines
1.8 KiB
Java
package dev.kske.minesweeper;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Font;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Iterator;
|
|
import java.util.Set;
|
|
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JTable;
|
|
import javax.swing.SwingConstants;
|
|
|
|
/**
|
|
* Project: <strong>Minesweeper</strong><br>
|
|
* File: <strong>ScoreDialog.java</strong><br>
|
|
* Created: <strong>16.04.2019</strong><br>
|
|
* Author: <strong>Kai S. K. Engelbart</strong>
|
|
*/
|
|
public class ScoreDialog extends JDialog {
|
|
|
|
private static final long serialVersionUID = 3637727047056147815L;
|
|
private JTable mtable;
|
|
|
|
/**
|
|
* Create the dialog.
|
|
*/
|
|
public ScoreDialog(Set<Score> scores) {
|
|
setBounds(100, 100, 450, 300);
|
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
getContentPane().setLayout(new BorderLayout(0, 0));
|
|
|
|
String[] columnNames = {"Name", "Game duration", "Board Config", "Date"};
|
|
String[][] data = new String[scores.size()][4];
|
|
Iterator<Score> iter = scores.iterator();
|
|
for(int i = 0; i < data.length; i++) {
|
|
Score s = iter.next();
|
|
data[i][0] = s.getName();
|
|
data[i][1] = String.valueOf(s.getDuration());
|
|
data[i][2] = s.getBoardConfig().toString();
|
|
data[i][3] = new SimpleDateFormat().format(s.getDate());
|
|
}
|
|
|
|
mtable = new JTable(data, columnNames);
|
|
getContentPane().add(mtable);
|
|
|
|
JPanel panel = new JPanel();
|
|
getContentPane().add(panel, BorderLayout.NORTH);
|
|
panel.setLayout(new BorderLayout(0, 0));
|
|
|
|
panel.add(mtable.getTableHeader(), BorderLayout.CENTER);
|
|
|
|
JLabel lblHighscores = new JLabel("Highscores");
|
|
panel.add(lblHighscores, BorderLayout.NORTH);
|
|
lblHighscores.setFont(new Font("Tahoma", Font.BOLD, 16));
|
|
lblHighscores.setHorizontalAlignment(SwingConstants.CENTER);
|
|
}
|
|
}
|