forked from DVedaa/Type-Speed-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
End.java
59 lines (50 loc) · 1.55 KB
/
End.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.*;
public class End extends JFrame implements ActionListener {
private Button quitButton;
private Button restartButton;
public End() {
try {
final Image backgroundImage = javax.imageio.ImageIO.read(new File("bg.jpg"));
setContentPane(new JPanel(new BorderLayout()) {
@Override public void paintComponent(Graphics g) {
g.drawImage(backgroundImage, 0, 0, null);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
setLayout(new FlowLayout());
quitButton = new Button("Quit Game");
quitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
restartButton = new Button("Restart Game");
restartButton.addActionListener(this);
add(quitButton);
add(restartButton);
setTitle("Game Over!");
setSize(400, 400);
setVisible(true);
}
public static void main(String[] args){
new End();
}
@Override
public void actionPerformed(ActionEvent arg0) {
try {
TyperManPanel newgame = new TyperManPanel();
this.setVisible(false);
newgame.setVisible(true);
this.dispose();
} catch (FileNotFoundException E) {
System.exit(0);
}
}
}