-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardButton.java
More file actions
49 lines (47 loc) · 1 KB
/
BoardButton.java
File metadata and controls
49 lines (47 loc) · 1 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BoardButton extends JButton implements ActionListener
{
public boolean alive;
public JFrame frame;
public JPanel board;
public int surround;
public BoardButton(JFrame fr, JPanel b)
{
super();
board=b;
frame=fr;
alive=false;
this.setBackground(Color.WHITE);
this.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
alive=!alive;
if(alive)
{
setBackground(Color.BLACK);
}
else
setBackground(Color.WHITE);
}
public void eval()
{
if(surround <2)
{
alive=false;
setBackground(Color.WHITE);
}
if(surround>3)
{
alive=false;
setBackground(Color.WHITE);
}
if(surround==3)
{
alive=true;
setBackground(Color.BLACK);
}
}
}