JavaFX: Task will not update UI


Question

I'm working on an Omaha online poker client written in javaFX+java.

I need to show an anchorPane containing 3 buttons after control.call() finishes executing. I know for a fact that control.call() finishes executing but for some reason task.setOnSucceeded(new EventHandler() {'s handle method does not update the User interface.

What am I doing wrong?

public void newRound() {

    sog = StateOfGame.PREFLOP;       

     ControlGameOnNewThread control = new ControlGameOnNewThread();

    Task task = new Task() {

        @Override
        protected Object call() throws Exception {
            control.call();
            return null;
        }
    };

    task.setOnSucceeded(new EventHandler() {

        @Override
        public void handle(Event event) {
            if (client.getAction() == FirstToAct.me) {
                System.out.println("Task finsished");
                    showOptions(client.getToCall());
                    opponentBetField.setText(new Integer(opp.chipsInvested).toString());
                    myBetField.setText(new Integer(client.chipsInvested).toString());
                    System.out.println("Task finsished");

            }
    }
    });


    new Thread(task).start();


}
1
1
4/22/2014 2:18:37 AM

As you override the call() method, you can override the succeeded() method: (See last example in the javadoc of Task.)

@Override protected void succeeded() {
     super.succeeded();
     updateMessage("Done!");
}

succeeded() is already called on the JavaFX Application Thread, so you do not need to do this for yourself.

Are you sure, that the code in your handle method isn't called? Maybe a NullPointerException is thrown, which you might not see? Is the comparison working as expected?

Try moving the code with if (client.getAction()... into the overridden succeeded() method and put a println before the if-statement in order to see whether it is called or not.

(EDIT: typos)

1
4/23/2014 9:44:28 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon