-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameSetup.java
More file actions
69 lines (61 loc) · 1.96 KB
/
Copy pathGameSetup.java
File metadata and controls
69 lines (61 loc) · 1.96 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
58
59
60
61
62
63
64
65
66
67
68
69
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class GameSetup extends JFrame {
JPanel menu;
JTextField size;
String sizeText;
public GameSetup() {
this.setTitle("Minesweeper Setup");
this.setSize(1050, 350);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setResizable(false);
this.setContentPane(createMenu());
}
private JPanel createMenu() {
menu = new JPanel();
menu.setBackground(new Color(206, 202, 212));
ImageIcon image = new ImageIcon("MinesweeperTitle.png");
JLabel iconLbl = new JLabel();
iconLbl.setIcon(image);
menu.add(iconLbl);
JLabel gameSize = new JLabel("Game Size:");
gameSize.setFont(new Font("Verdana", Font.PLAIN, 20));
menu.add(gameSize);
size = new JTextField(2);
size.setFont(new Font("Verdana", Font.PLAIN, 20));
menu.add(size);
JButton play = new JButton("Play");
play.addActionListener(new PlayButtonListener());
menu.add(play);
return menu;
}
class PlayButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
sizeText = size.getText();
try {
Integer comp = Integer.parseInt(sizeText);
if (comp < 3 || comp > 16) {
JOptionPane.showMessageDialog(null, "Minimum game board size is 3. Maximum game board size is 16. Please try again.");
} else {
dispose();
Board instance = new Board(comp);
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Invalid numerical input. Please try again.");
}
}
}
}