From d0594cba7ed93ca3c1805643c5e53b752cfbf5bd Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 15:55:18 +0100 Subject: [PATCH] Flagging on right click --- src/main/java/Minesweeper/Cell.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/Minesweeper/Cell.java b/src/main/java/Minesweeper/Cell.java index fc7d393..80e9aac 100644 --- a/src/main/java/Minesweeper/Cell.java +++ b/src/main/java/Minesweeper/Cell.java @@ -4,6 +4,8 @@ import java.awt.Color; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import javax.swing.JButton; @@ -32,6 +34,17 @@ public class Cell extends JButton { 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() { @@ -42,6 +55,14 @@ public class Cell extends JButton { } } + protected void OnMouseRightClick() { + if (flagged) { + flagged = false; + } else { + flagged = true; + } + } + public void update() { if (type == CellType.Number) { setText(String.valueOf(value));