-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreBoard.java
99 lines (86 loc) · 2.54 KB
/
ScoreBoard.java
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.*;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import static java.lang.System.*;
import java.awt.*;
import javax.swing.*;
import java.util.Scanner;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.util.*;
import java.io.*;
/**
* A class for reading the highscore file, and displaying all the highscores, gets used when gameover
*/
public class ScoreBoard extends JFrame{
JTextField firstName;
JTextField firstScore;
JTextField secondName;
JTextField secondScore;
JTextField thirdName;
JTextField thirdScore;
JButton button;
/**
*Creates the gui board
*/
public ScoreBoard(){
createComponents();
this.setSize(300, 300);
this.setResizable(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
/**
*Creates the panel and adds all of the components to the panel
*/
public void createComponents(){
createText();
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout( new GridLayout(3,2));
panel.add(firstName);
panel.add(firstScore);
panel.add(secondName);
panel.add(secondScore);
panel.add(thirdName);
panel.add(thirdScore);
mainPanel.add(panel, BorderLayout.CENTER);
this.add(mainPanel);
}
/**
*Creates textfields that display the names and scores on the scoreboard
*By using a file reader to read off of the ScoreList text
*/
public void createText(){
firstName = new JTextField(20);
firstScore = new JTextField(10);
secondName = new JTextField(20);
secondScore = new JTextField(10);
thirdName = new JTextField(20);
thirdScore = new JTextField(10);
try{
FileReader reader = new FileReader("scoreList.txt");
Scanner in = new Scanner(reader);
firstName.setText("Legend of Legends: " + in.next());
firstScore.setText(in.next() + " Points");
secondName.setText("Second Heir: " + in.next());
secondScore.setText(in.next() + " Points");
thirdName.setText("Legend's Guardian: " + in.next());
thirdScore.setText(in.next() + " Points");
reader.close();
} catch(Exception e) {
System.out.println("Someting wong");
}
}
}