-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenu.java
More file actions
57 lines (52 loc) · 1.84 KB
/
Copy pathMainMenu.java
File metadata and controls
57 lines (52 loc) · 1.84 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MainMenu extends JPanel implements ActionListener {
GameFrame gf;
JPanel buttons = new JPanel(new GridBagLayout());
JLabel title = new JLabel("MEMORY CARDS");
JButton startbtn = new JButton("start new game");
JButton settingsbtn = new JButton("settings");
JButton scoresbtn = new JButton("scores");
JButton exitbtn = new JButton("exit");
public MainMenu(GameFrame gf) {
this.gf = gf;
setLayout(new BorderLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 5, 5, 5); // Padding
gbc.gridy++;
buttons.add(startbtn, gbc);
gbc.gridy++;
buttons.add(settingsbtn, gbc);
gbc.gridy++;
buttons.add(scoresbtn, gbc);
gbc.gridy++;
buttons.add(exitbtn, gbc);
title.setHorizontalAlignment(SwingConstants.CENTER);
title.setFont(Styles.gameTitle);
title.setBorder(BorderFactory.createEmptyBorder(150,100,0,100));
add(title, "North");
add(buttons, "Center");
startbtn.addActionListener(this);
settingsbtn.addActionListener(this);
scoresbtn.addActionListener(this);
exitbtn.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
Sounds.playClickSound();
if(src == startbtn)
gf.cl.show(gf.getContentPane(),"game");
else if(src == settingsbtn)
gf.cl.show(gf.getContentPane(),"settings");
else if(src == scoresbtn)
gf.cl.show(gf.getContentPane(),"scores");
else
gf.dispose();
}
}