-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.java
More file actions
53 lines (47 loc) · 1.34 KB
/
Options.java
File metadata and controls
53 lines (47 loc) · 1.34 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
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Options extends JPanel implements ActionListener {
private Game game;
private JButton aIMove;
private JButton undo;
private JButton redo;
public Options(Game gm) {
this.game = gm;
aIMove = new JButton();
setButton(aIMove, "AI Move");
undo = new JButton();
setButton(undo, "Undo");
redo = new JButton();
setButton(redo, "Redo");
setLayout(new GridLayout(1, 3));
setVisible(true);
}
private void setButton(JButton button, String text) {
button.setText(text);
button.setBackground(new Color(240, 240, 255));
button.setFont(new Font("Geneva", Font.BOLD, 30));
button.setFocusable(false);
button.addActionListener(this);
add(button);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == aIMove) {
this.game.aiMove();
} else if (e.getSource() == undo) {
this.game.undo();
} else if (e.getSource() == redo) {
this.game.redo();
}
}
public void gameover() {
aIMove.setEnabled(false);
undo.setEnabled(false);
redo.setEnabled(false);
}
}