我必须制作一个Minesweeper GUI,但我无法弄清楚如何使每个按钮拥有它自己的mouseAdapter.单击按钮时,它会更改屏幕上的每个按钮,而不是我单击的按钮.我可以就如何做到这一点有一些指示吗?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MinePanel extends JPanel
{
private final int ROWS = 10;
private final int COLUMNS = 10;
private int numOfMines;
private double probability;
private JLabel statusBar;
private int minesLeft;
private JButton Minefield[][];
private boolean hasMine = false;
private int curRow = 0;
private int curCol = 0;
private JButton cell;
public MinePanel()
{
setLayout(new GridLayout(10, 10));
Minefield = new JButton[ROWS][COLUMNS];
//menuStuff();
buildButtonField();
}
//I will eventually want to create a menu, …Run Code Online (Sandbox Code Playgroud)