-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScoreboard.java
More file actions
64 lines (48 loc) · 1.68 KB
/
Scoreboard.java
File metadata and controls
64 lines (48 loc) · 1.68 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
//Justin Baldeosingh
//816021226
//COMP 3609 - Assignment 1
import javax.swing.*; // need this for GUI objects
import java.awt.*; // need this for Layout Managers
import static java.lang.Integer.parseInt;
public class Scoreboard extends JPanel {
//Declares labels for lives and score.
private JLabel livesLabel;
private JLabel scoreLabel;
//Declares text fields for lives and score.
private JTextField livesTF;
private JTextField scoreTF;
public Scoreboard() {
//Creates the lives label and customizes it.
livesLabel = new JLabel ("Lives: ");
livesLabel.setOpaque(true);
livesLabel.setBackground(new Color(196, 196, 196));
//Creates the score label.
scoreLabel = new JLabel ("Score: ");
//Create lives and score text fields.
livesTF = new JTextField (25);
livesTF.setEditable(false);
livesTF.setBackground(new Color(196, 196, 196));
scoreTF = new JTextField (25);
scoreTF.setEditable(false);
// Creates the info panel and sets the layout.
GridLayout gridLayout = new GridLayout(1, 4);
this.setLayout(gridLayout);
//Adds the respective labels and fields (game information) to the panel.
this.add(livesLabel);
this.add(livesTF);
this.add(scoreLabel);
this.add(scoreTF);
}
public void setLives(String lives) {
this.livesTF.setText(lives);
}
public int getLives() {
return parseInt(this.livesTF.getText());
}
public void setScore(String score) {
this.scoreTF.setText(score);
}
public int getScore() {
return parseInt(this.scoreTF.getText());
}
}