This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JavaFX and the fly likes Thread and UI (Application) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JavaFX
Reply Bookmark "Thread and UI (Application) "communication"" Watch "Thread and UI (Application) "communication"" New topic
Author

Thread and UI (Application) "communication"

L Purcell
Greenhorn

Joined: Feb 19, 2012
Posts: 12
Here's the scenario: A "start" button is clicked which sets up a Service/Task which includes I/O with a device. A changeListener is started, and the "start" button handler ends. Eventually, the changeListener detects a "change" and does its thing with the I/O device. NOW my question: How do I "notify" the user that the "change" (event) has occurred? "Update message" doesn't do anything since the "start" button routine has ended. I know I'm missing something fundamental here, but I'm baffled. (This is my first foray into the Service/Task business...) (The code in all other respects works great.) Thanks! L (Here is the boiled-down code.)

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 925
    
    2

This is an interesting scenario. The usual examples for tasks have a blocking task happening within the Task and so updation of GUI can be done. But, in this case, you just register a callback handler. Actually, in this case, you may not need the task to just install the listener.
And from within the listener, You can wrap the UI update call in Platform.runLater()


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
L Purcell
Greenhorn

Joined: Feb 19, 2012
Posts: 12
Ranga, thanks for the reply. I decided to keep the service/task since the setup part (which I omitted to save space) may hang/block. However, I solved the "communication" problem by BINDING the text in a textArea with the messageProperty in the Task! Perhaps this has the same effect as you were suggesting (by different means)?? Anyway, it all appears to work now, and I'm off struggling with the Android client code... Thanks again! L
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 925
    
    2

Ok, I see where the task was needed. I am not sure about the binding, because, I have never tried it myself - that sounds interesting.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Thread and UI (Application) "communication"
 
Similar Threads
JavaFX, Scene Builder, and basic issues with threads/tasks
javafax, button action..NEED HELP PLEASE!!!
Need help with thread pool issue..
Null pointer exception probably due to synchronisation issues; problem in starting activity
USB Modem stuck while submitting data