-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreboard.java
55 lines (48 loc) · 1.69 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
import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.util.Scanner;
import java.io.*;
public class Scoreboard extends JPanel{
int width = width();
int height = height();
public Scoreboard(){}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.BLACK);
g.fillRect(0,0,width,height);
g.setColor(Color.WHITE);
Random fromage = new Random();
for(int i = 0; i <= (width/3); i++){//randomly generate stars
g.fillOval(fromage.nextInt(width), fromage.nextInt(height), 5, 5);
}
File file = new File("score.txt");
try{
Scanner doc = new Scanner(file);
int start = 10;
while(doc.hasNextLine()){
g.drawString(doc.nextLine(),10,start);
start+= 20;
}
doc.close();
}catch(FileNotFoundException e){
System.out.println("File \"score.txt\" improperly installed");
}
}
public static void main(String[] args){
JFrame frame = new JFrame("Local Scores");
Scoreboard score = new Scoreboard();
frame.setSize(600,600);
frame.add(score);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
public int width(){
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
return (int)screenSize.getWidth() + 1;
}
public int height(){
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
return (int)screenSize.getHeight() + 1;
}
}