-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainScreen.java
More file actions
55 lines (43 loc) · 1.51 KB
/
Copy pathMainScreen.java
File metadata and controls
55 lines (43 loc) · 1.51 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MainScreen implements ActionListener {
public JFrame frame = new JFrame();
public GridBagConstraints c = new GridBagConstraints();
public JButton myButton = new JButton("Start");
public JLabel myLabel = new JLabel("Minesweeper");
public MainScreen() {
myButton.setBounds(160,160,100,50);
myButton.setPreferredSize(new Dimension(160,80));
myButton.setFocusable(false);
myButton.addActionListener(this);
myLabel.setFont(new Font("Arial", Font.BOLD, 24));
myLabel.setHorizontalAlignment(JLabel.CENTER);
myLabel.setPreferredSize(new Dimension(200,200));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Minesweeper");
frame.setSize(420,420);
frame.setLayout(new GridBagLayout());
frame.setLocationRelativeTo(null);
frame.setVisible(true);
c.gridx = 0;
c.gridy = 0;
c.ipadx = 0;
c.ipady = 2;
c.weightx = 1.0;
c.weighty = 1.0;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.CENTER;
frame.add(myLabel, c);
c.gridy = 1;
frame.add(myButton, c);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == myButton){
GameScreen myScreen = new GameScreen(5,5,23);
frame.dispose();
}
}
}