我正在用java做一个棋盘游戏,我想制作一个开始按钮来开始游戏。主要函数是一个递归函数(gameloop),我在 ActionListener 中调用该函数,当我单击按钮时,它被卡住了。
ActionListener startListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
gameFrame.remove(startB);
gameFrame.add(boardPanel, gbc);
gameFrame.revalidate();
Game.gameLoop(); //the main recursive function
}
};
编辑:我使用了 SwingWorker,它工作得很好,谢谢你的帮助
最佳答案
尝试这样的事情:
@Override
public void actionPerformed(ActionEvent e) {
gameFrame.remove(startB);
gameFrame.add(boardPanel, gbc);
gameFrame.revalidate();
new Thread(){
public void run(){
Game.gameLoop(); //the main recursive function
}
}.start();
}
关于java - JButton 在单击时卡住(因为我在 ActionListener 中启动递归函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54167285/