-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewOldScoresWindow.java
More file actions
87 lines (72 loc) · 2.27 KB
/
ViewOldScoresWindow.java
File metadata and controls
87 lines (72 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.ArrayList;
/** Window that pops up when user selects "View Recent Scores" in the menubar.
*
* @author Gemma Smith <gemma.smith@tufts.edu>
* @version 1.0
* @since 2013-12-09
*/
public class ViewOldScoresWindow extends JFrame implements ActionListener
{
private JFrame window;
private Main main;
private ArrayList<Score> scores;
private MyButton close;
public ViewOldScoresWindow(Main mn)
{
super("View Recent Scores");
window = this;
main = mn;
scores = main.getScores();
setSize(425,350);
setLocation(100,100);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setOpaque(true);
panel.setBackground(Color.WHITE);
JLabel title = new JLabel ("Recent scores");
title.setFont(new Font("SansSerif", Font.BOLD, 16));
title.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(title);
String htmlString = "<html><body><br>";
if (scores.isEmpty())
htmlString += "(You have not saved any scores since opening the "+
"program.)<br><br>";
else
{
htmlString += "Here are the scores you have saved since opening "+
"the program:<br><br>";
Score s;
for (int i=0; i<scores.size(); i++)
{
s = scores.get(i);
htmlString += s.getDate()+", "+s.getName()+": "+
"<br> "+
"Lobster Count: "+s.getLobsters()+
"<br> "+
"Life Count: "+s.getLife() + "<br>";
}
}
htmlString += "<br><br></body></html>";
JLabel listScores = new JLabel (htmlString, JLabel.CENTER);
listScores.setFont(new Font("SansSerif", Font.PLAIN, 12));
listScores.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(listScores);
close = new MyButton("Close", Color.BLACK, 12);
close.addActionListener(this);
close.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(close);
add(panel);
setVisible(true);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
window.setVisible(false);
main.closeWindow();
window.dispose();
}
}