-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.java
115 lines (81 loc) · 2.5 KB
/
Button.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Button extends JButton implements MouseListener{
boolean isBomb;
boolean hasBeenPressed;
int nearbyBombCount;
int row;
int col;
Button(){
this.isBomb = false;
this.hasBeenPressed = false;
this.addMouseListener(this);
setSize(100, 100);
}
Button(String s){
}
Button(boolean bomb, int surrounding, int newRow, int newCol){
row = newRow;
col = newCol;
isBomb = bomb;
nearbyBombCount = surrounding;
this.addMouseListener(this);
setSize(100, 100);
}
public void becomeBomb(){
this.isBomb = true;
}
public void countBombs(){//not going to be used
}
public void printNearbyBombs(){//prints to console
System.out.println(this.nearbyBombCount);
}
public void printIsBomb(){
System.out.println(this.isBomb);
}
@Override
public void mouseClicked(MouseEvent mouseEvent) {
//System.out.println("pressed");
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.getModifiers() == MouseEvent.BUTTON3_MASK) {
if(getText().equals("F")){
setText("");
} else if (getText().equals("")){
setText("F");
}
System.out.println("You right clicked on the button");
} else if(getText().equals("F")) {
//do nothing
} else{
if (isBomb) {
System.out.println("BOOM!!!");
setText("B");
} else {
if (!getText().equals("0") && nearbyBombCount == 0) {
//check u/d/r/l for other hidden 0's
//checkForZeros();
System.out.println("0-first time");
setText("0");
GridMain01.checkForZeros(row, col);
} else if (getText().equals(null)) {//&& nearbyBombCount == 0
System.out.println("words");
} else {
System.out.println(Integer.toString(nearbyBombCount));
setText(Integer.toString(nearbyBombCount));
}
}
}
}
@Override
public void mouseEntered(MouseEvent mouseEvent) {
}
@Override
public void mouseExited(MouseEvent mouseEvent) {
}
}