Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GUI出现问题,按钮未执行任何操作_Java_Swing - Fatal编程技术网

Java GUI出现问题,按钮未执行任何操作

Java GUI出现问题,按钮未执行任何操作,java,swing,Java,Swing,我对这段代码有一个问题,gridPanel的按钮不会被点击 注意:BKJpanel和BK1Jpanel是我创建的类,它们扩展了JPanel来编辑图标绘制 CustomJButton也是我创建的一个类,出于同样的原因扩展了JButton,它在初始化时将ActionListener作为其构造函数的参数,然后将AddActionListener添加到构造函数中以获取传递的ActionListener 另一个注意事项:Board是我制作的游戏引擎的一个类。这与问题无关,我认为:D public clas

我对这段代码有一个问题,gridPanel的按钮不会被点击

注意:BKJpanel和BK1Jpanel是我创建的类,它们扩展了JPanel来编辑图标绘制

CustomJButton也是我创建的一个类,出于同样的原因扩展了JButton,它在初始化时将ActionListener作为其构造函数的参数,然后将AddActionListener添加到构造函数中以获取传递的ActionListener

另一个注意事项: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);
                    }
                }
            }
        }
    }

InitGridButtons方法是在BoardConfig方法中调用的。您的问题是关于action listener的,但我在类定义之外的任何地方都没有看到action listener,在这种情况下,我看不到任何添加了listener的actionPerformed方法。请为您的问题提供相关代码。并提出一个具体的问题。没有发生什么?我在上面说过CustomJButton将侦听器作为一个参数,即不需要addActionListener,actionPerformed方法我没有使用它我使用了mouseClicked方法那么你在哪里添加鼠标侦听器呢?考虑发布一个运行示例。您没有提供足够的信息,甚至没有为我们提供足够的描述来帮助您