新游戏按钮导致Java游戏应用程序停止响应

时间:2017-10-28 02:56:20

标签: java user-interface javafx

我正在使用javaFX制作一个java扑克应用程序。我特别喜欢java和javaFX。当我的代码编译时,我似乎没有得到任何明确的错误,但是当我运行程序并点击按钮时,#34; New Game"按钮,我的应用程序停止响应,我不知道为什么。

Opponent类是一个抽象接口,在这个类中有四个类来描述对手的类型。

Opponent类声明为:

public abstract interface Opponent

和一种类型的对手写成:

public static class tightAggressiveOpponent extends Player
        implements Opponent

我在发布问题之前尝试解决此问题。如果有人能提供任何建议,我将不胜感激?实际按钮本身的代码是:

public void handleNewGameButtonAction(ActionEvent event) {
       run();
    }

public void run()
    {
        this.gameInfoText.set("Run method called");
        Table table = new Table();
        Deck deck = new Deck();
        Pot pot = new Pot();

        player1 = new Player("Oliver", false, pot, Boolean.valueOf(true));
        Opponent.tightAggressiveOpponent opponent = new Opponent.tightAggressiveOpponent("Jeremy (TA)", true, pot, table);
        player1.setOpponentPlayStyle(opponent.getPlayStyle());
        opponent.setOpponent(player1);

        playGame(player1, opponent, table, deck, pot);
    }

1 个答案:

答案 0 :(得分:0)

看起来你在方法playGame中有一个无限循环或阻塞操作。

您应该在后台线程中运行此方法。例如:

new Thread(new Runnable(){
    public void run(){
        playGame(player1, opponent, table, deck, pot);
    }
}).start();

此外,您不能/不应该从后台线程更新UI。因此,在playGame方法中使用如下代码来更新UI:

Platform.runLater(new Runnable(){
    public void run(){
        textArea.setText("something");
    }
});
相关问题