Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread and UI (Application) "communication"

 
L Purcell
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
L Purcell
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic