forked from awesomeamit1998/Type-Speed-Game
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMenu.java
46 lines (43 loc) · 1.07 KB
/
Menu.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File ;
import java.io.* ;
public class Menu extends JFrame implements ActionListener {
private Button btn1;
public Menu(){
try {
final Image backgroundImage = javax.imageio.ImageIO.read(new File("new-game.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());
btn1 = new Button("New Game");
btn1.addActionListener(this); //this refers to your current frame
add(btn1);
setTitle("Welcome to Typer-Man-Game");
setSize(400, 400);
setVisible(true);
}
public static void main(String[] args){
new Menu();
}
@Override
public void actionPerformed(ActionEvent e) {
try {
TyperManPanel newgame = new TyperManPanel();
this.setVisible(false);
newgame.setVisible(true);
this.dispose();
}
catch (FileNotFoundException E)
{
System.exit(0);
}
}
}