-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScore.java
More file actions
40 lines (35 loc) · 1.11 KB
/
Score.java
File metadata and controls
40 lines (35 loc) · 1.11 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.*;
/**
* Created by Nishant Chintala
*/
//The Score Class is a JPanel Object that draws the score number on a JFrame.
public class Score extends JPanel {
JFrame jf;
public int score;
public Score(int x, int y, JFrame frame, int aScore){
this.setSize(400, 25);
this.setLocation(x,y);
score = aScore;
jf = frame;
jf.add(this);
}
//Paints the current Score object on the JFrame.
protected void paintComponent(Graphics t) {
super.paintComponent(t);
Font f = new Font("Verdana", Font.BOLD, 25);
t.setFont(f);
t.drawString("Score: " + Integer.toString(score), 0, 25);
}
//Accepts an int and adds that numbe to the current score and returns the new score number as an int.
public int increaseScore(int num){
score += num;
return score;
}
}