0

I am working on a JavaFX, Jfoenix desktop application where I have multiple FXML views. The application is supposed to recognize in real-time when a specific embedded device was connected or disconnected. Unfortunately, there is no interrupt function for this, so I am forced to constantly pool in a separate thread running from the main view. The thing is, I have to detect this change (when a device is connected and disconnected) from different views, not just on the main one. And since every view has its own controller and many GUI elements are injected using SceneBuilder, I cannot touch any of those, so I can't make a listener on a TextBox for example.

Is there any way that I could constantly listen in other views for something like a boolean flag change that was made in the pooling thread from the main view?

Something like this, listening for changes of the boolean variable: isHiConnected. This code is running in a JavaFX Service that implements a Task:

if (textName != "Disconnected") {
    if(!recentChange1) {
        isHiConnected = true;
        recentChange1 = true;
        recentChange2 = false;
    }
} else {
    if(!recentChange2) {
        isHiConnected = false;
        recentChange2 = true;
        recentChange1 = false;
    }
}
Jose Da Silva Gomes
  • 3,814
  • 3
  • 24
  • 34
John Szatmari
  • 375
  • 4
  • 11
  • 1
    Use [JavaFX properties](http://www.oracle.com/pls/topic/lookup?ctx=javase80&id=JFXBD107) (e.g. `BooleanProperty` in this case) instead of primitive variables. Note also the `if` statement in your code snippet is broken: `textName != "Disconnected"` should be `! (textName.equals("Disconnected"))`. – James_D Apr 05 '18 at 14:46
  • 1
    Furthermore it would be a good idea to move such a flag from the view/controller to a model. – fabian Apr 05 '18 at 14:47

0 Answers0