-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainFormForGame.java
65 lines (56 loc) · 1.96 KB
/
MainFormForGame.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
60
61
62
63
64
65
package TicTacToe;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MainFormForGame extends JFrame {
public MainFormForGame() {
// name of window
setTitle("Tic Tac Toe");
setBounds(300, 300, 455, 500);
setResizable(false);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
GameFunction gameField = new GameFunction();
JPanel buttonPanel = new JPanel(new GridLayout());
add(gameField, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
JButton btnStart = new JButton("Start new game");
btnStart.setFocusable(false);
JButton btnEnd = new JButton("Exit");
btnEnd.setFocusable(false);
JButton btnToSettings = new JButton("Settings");
btnToSettings.setFocusable(false);
buttonPanel.add(btnEnd);
buttonPanel.add(btnToSettings);
buttonPanel.add(btnStart);
setVisible(true);
//stop program
btnEnd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnEnd) {
System.exit(0);
}
}
});
// return to setting window
btnToSettings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnToSettings) {
GameSettings gameSettings = new GameSettings();
GameFunction.gameMode = 1;
dispose();
}
}
});
btnStart.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnStart) {
gameField.newGame();
}
}
});
}
}