在javafx中导致gui冻结的旋转转换

cbwuti44  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(208)

一般来说,我不想寻求帮助,当谈到修复错误,但是,我有一个非常奇怪的我花了两天时间试图修复它没有任何成功。我的类基本上是一个轮盘赌与多个困难,所以,我用一个piechart来改变困难和重绘轮盘赌快速和冷静的动画,随piechart,然而,方法,使我的轮盘赌滚动到一定的Angular 有一个大问题,在rotatetransition结束后,图形用户界面完全冻结。我不知道´我不知道为什么,因为我在其他类中有其他的旋转变换,它们工作得很好,而且,如果我删除旋转变换或在其中使用其他组件(我尝试使用图像而不是piechart),它工作得很好。我不知道´我不知道piechart是否有什么特别的东西使它无法与rotatetransition一起使用,而且冻结的唯一例外是允许我再次下注的按钮,是的,我已经尝试了“platform.runlater()”

@Override
    public void initialize(URL url, ResourceBundle rb) {
        rotateTransition = new RotateTransition();
        rotateTransition.setNode(pieChart);
        rotateTransition.setDuration(Duration.seconds(1));
        rotateTransition.setByAngle(-360);
        rotateTransition.setCycleCount(1);
        rotateTransition.setAutoReverse(false);

        pieChart.setData(dataForX1_5);
        pieChart.setStartAngle(90);
        applyDataWithCustomColor(dataForX1_5, "green", "red");

        betButton.setOnAction(eh -> {
            double betMultiplier=1.5;
            if(rbX1_5==group.getSelectedToggle()){
                pieChart.setData(dataForX1_5);
                applyDataWithCustomColor(dataForX1_5, "green", "red");
                betMultiplier=1.5;
            }
            if(rbX2==group.getSelectedToggle()){
                pieChart.setData(dataForX2);
                applyDataWithCustomColor(dataForX2, "green", "red");
                betMultiplier=2;
            }
            if(rbX5==group.getSelectedToggle()){
                pieChart.setData(dataForX5);
                applyDataWithCustomColor(dataForX5, "green", "red");
                betMultiplier=5;
            }
            if(rbX10==group.getSelectedToggle()){
                pieChart.setData(dataForX10);
                applyDataWithCustomColor(dataForX10, "green", "red");
                betMultiplier=10;
            }
            if(rbX25==group.getSelectedToggle()){
                pieChart.setData(dataForX25);
                applyDataWithCustomColor(dataForX25, "green", "red");
                betMultiplier=25;
            }
            if(rbX50==group.getSelectedToggle()){
                pieChart.setData(dataForX50);
                applyDataWithCustomColor(dataForX50, "green", "red");
                betMultiplier=50;
            }

            try {
                int betAmount = betAmountSpinner.getValue();
                int spectedResult = (int) (betAmount * betMultiplier);
                if (coins >= betAmount) {
                    dataOutputStream.writeUTF("PlaceBetOnUpgrade");
                    dataOutputStream.writeInt(betAmount);
                    dataOutputStream.writeInt(spectedResult);
                    if (dataInputStream.readBoolean()) {
                        int result = dataInputStream.readInt();
                        int payment = dataInputStream.readInt();
                        coins = coins - betAmount;
                        rotateTo(result, payment);
                        updateCoinsLabel();
                    }
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        });
    }

    private void rotateTo(int result, int payment) {
        rotateTransition.setToAngle(result * 3.60);
        rotateTransition.setOnFinished(rotateEvent -> {
            if (0 == payment) {
                resultLabel.setText("Lost");
            } else {
                resultLabel.setText("Win");
                coins = coins + payment;
                updateCoinsLabel();
            }
        });
        rotateTransition.play();
    }

    private void updateCoinsLabel() {
        coinsLabel.setText(String.valueOf(coins));
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题