I'm lately messing up with handling joystick in java.So here is the thing. I wrote a simple class that handle input from joystick, but I'm no certain if I'm doing it well. Here is what I want to achieve. So i have joypad, I'm using jinput from LWJGL 2, and want to bind axis and buttons state to Javafx application, and than send it to my arduino rc car. It's working, but I'm just wondering is there more efficient way to read joystick input? Now I have that thread which never ends and read joystick value. I was looking for some event handler but non of them works. If anyone have some suggesions I would appreciate it.  If none of above is clear so here is TODO list:I have joypad which I'm reading data.I'm wonder what is most efficient way to read data from joystick?I'm using LWJGL 2 jInput.Is there any way to get rid of that thread?Controller.classpackage wcc;import java.util.ArrayList;import org.lwjgl.input.Controller;import javafx.beans.property.SimpleBooleanProperty;import javafx.beans.property.SimpleFloatProperty;public class FXController implements Runnable{    private boolean threadAlive = true;    private Controller controller;    private ArrayList<SimpleFloatProperty> axis = new ArrayList<>();    private ArrayList<SimpleBooleanProperty> buttons = new ArrayList<>();    public FXController(Controller controller){        this.controller = controller;        for(int i = 0; i < this.controller.getAxisCount(); i++){            this.axis.add(new SimpleFloatProperty(0));        }        for(int i = 0; i < this.controller.getButtonCount(); i++){            this.buttons.add(new SimpleBooleanProperty(false));        }    }    public ArrayList<SimpleFloatProperty> getAxisProperty(){        return this.axis;    }    public ArrayList<SimpleBooleanProperty> getButtonProperty(){        return this.buttons;    }    public Controller getController(){        return this.controller;    }    public void stopThread(){        this.threadAlive = false;    }    public boolean isThreadAlive(){        return this.threadAlive;    }    @Override    public void run() {        while(threadAlive){            for(int i = 0; i < this.controller.getAxisCount(); i++){                this.axis.get(i).set(this.controller.getAxisValue(i)+1);            }            for(int i = 0; i < this.controller.getButtonCount(); i++){                this.buttons.get(i).set(this.controller.isButtonPressed(i));            }            this.controller.poll();        }    }}@FXML Controllerpackage wcc;import java.net.URL;import java.util.ResourceBundle;import org.lwjgl.input.Controllers;import javafx.fxml.FXML;import javafx.fxml.Initializable;import javafx.geometry.Insets;import javafx.scene.control.ComboBox;import javafx.scene.control.ProgressBar;import javafx.scene.control.TitledPane;import javafx.scene.control.ToggleButton;import javafx.scene.image.Image;import javafx.scene.image.ImageView;import javafx.scene.layout.GridPane;import javafx.scene.layout.TilePane;import javafx.scene.layout.VBox;public class wccController implements Initializable{    @FXML GridPane _ROOT;    @FXML ComboBox<String> _CONTROLLERS;    @FXML VBox _AXISBOX;    @FXML TilePane _BUTTONSGRID;    @FXML ImageView _CAMERAVIEW;    FXController selected = null;    @Override public void initialize(URL arg0, ResourceBundle arg1) {        try{            Controllers.create();            for(int i = 0; i < Controllers.getControllerCount(); i++){                this._CONTROLLERS.getItems().addAll(Controllers.getController(i).getName());            }            new Thread(new Runnable(){                @Override                public void run() {                    while(true){                        _CAMERAVIEW.setImage(new Image(http://192.168.1.171:8080/shot.jpg));                    }                }            },CameraThread).start();;        } catch(Exception ex){            ex.printStackTrace();        }    }    @FXML private void onControllerSelectionChanged(){        this._AXISBOX.getChildren().clear();        if(this.selected != null){            this.selected.stopThread();        }        this.selected = new FXController(Controllers.getController(this._CONTROLLERS.getSelectionModel().getSelectedIndex()));        new Thread(this.selected, Controller thread.).start();        for(int i = 0; i < this.selected.getController().getAxisCount(); i++){            ProgressBar axisValue = new ProgressBar();                axisValue.setPadding(new Insets(8));                axisValue.progressProperty().bind(this.selected.getAxisProperty().get(i).divide(2));            TitledPane axisName = new TitledPane();                axisName.setText(AXIS: [  + this.selected.getController().getAxisName(i) +  ]);                axisName.setCollapsible(false);                axisName.setContent(axisValue);            this._AXISBOX.getChildren().add(axisName);        }        this._BUTTONSGRID.getChildren().clear();        this._BUTTONSGRID.setPrefColumns(4);        for(int i = 0; i < this.selected.getController().getButtonCount(); i++){            ToggleButton buttonState = new ToggleButton([O]);                buttonState.setPadding(new Insets(8));                buttonState.setDisable(true);                buttonState.selectedProperty().bind(this.selected.getButtonProperty().get(i));            TitledPane buttonName = new TitledPane();                buttonName.setText([  + this.selected.getController().getButtonName(i) +  ]);                buttonName.setCollapsible(false);                buttonName.setContent(buttonState);            this._BUTTONSGRID.getChildren().add(buttonName);        }    }}
Creating JavaFX bindable property readed from joystick
java;controller;javafx