9781430265740_Fig07-09.jpg

Figure 7-9. The WorkerAndTaskExample program after the task succeeded

If, instead of letting the task finish normally, we click the Cancel button, the task will finish immediately and the screenshot in Figure 7-10 results. Notice that the State field has the value CANCELLED now. The Value field contains the string we passed to the updateValue() method when the task was cancelled. When we detect that the task is cancelled, we have two choices of exiting from the method body. In the program in Listing 7-7, we chose to update the Value and return from the method. We could also have chosen to exit from the method body by throwing a RuntimeException ...

Get Pro JavaFX 8 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.