我的代码有问题,gridPanel的按钮不会被点击。
注意:BKJpanel和BK1Jpanel是我制作的扩展JPanel以编辑图标的类。
CustomJButton也是一个由于同样的原因扩展JButton的类,它在初始化时将ActionListener作为它的构造函数的参数,然后将addActionListenener添加到构造函数中以获取传递的ActionListenener。
另一个注意事项:Board是我制作的一类游戏引擎。它与我认为的问题没有任何关系:D
public class BoardGUI extends JFrame implements ActionListener, MouseListener {
JPanel WholePanels;
BKJpanel gridPanel;
BK1Jpanel EastPanel;
JPanel NorthPanel;
CustomJButton[][] btn;
Board santorini;
static CustomJButton newGame;
static Board rePlay;
static JLabel labe3;
static JLabel labe4;
public BoardGUI(Board santorini) {
super();
setTitle("SANTORINI");
setSize(1366, 766);
setLocation(0, 0);
this.setExtendedState(Frame.MAXIMIZED_BOTH);
this.santorini = santorini;
rePlay = santorini;
InitBoardPanels();
BoardConfig();
setNewIcons();
WindowDestroyer wd = new WindowDestroyer();
addWindowListener(wd);
}
public void InitGridButtons() {
btn = new CustomJButton[5][5];
for (int i = 0; i < btn.length; i++) {
for (int j = 0; j < btn[i].length; j++) {
btn[i][j] = new CustomJButton(null, 1.5f, "Ready", this);
gridPanel.add(btn[i][j]);
}
}
}
public void mouseClicked(MouseEvent arg0) {
if (arg0.getSource() == newGame) {
this.santorini = rePlay;
} else {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if ((arg0.getSource() == btn[i][j])) {
Logic(i, j);
}
}
}
}
}