Browse Source

Flagging on right click

feature_Minesweeper_Playfield
kfkama 3 years ago
parent
commit
d0594cba7e
  1. 21
      src/main/java/Minesweeper/Cell.java

21
src/main/java/Minesweeper/Cell.java

@ -4,6 +4,8 @@ import java.awt.Color;
import java.awt.Point; import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton; import javax.swing.JButton;
@ -32,6 +34,17 @@ public class Cell extends JButton {
OnMouseClick(); OnMouseClick();
} }
}); });
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
super.mousePressed(e);
if (e.getButton() == 3) {
OnMouseRightClick();
}
}
});
} }
protected void OnMouseClick() { protected void OnMouseClick() {
@ -42,6 +55,14 @@ public class Cell extends JButton {
} }
} }
protected void OnMouseRightClick() {
if (flagged) {
flagged = false;
} else {
flagged = true;
}
}
public void update() { public void update() {
if (type == CellType.Number) { if (type == CellType.Number) {
setText(String.valueOf(value)); setText(String.valueOf(value));

Loading…
Cancel
Save