You use 2 different instances of the Movements
class (Movements Movements = new Movements();
in OpenPilot
and FXMLDocumentController
). Since you don't use static fields / methods, you won't get any data from one instance to the other. You have to get the Movements
object from the controller:
Controller:
public class FXMLDocumentController implements Initializable {
Movements movements = new Movements();
public Movements getMovements() {
return movements;
}
@FXML public Slider SpeedSlider;
@FXML public Slider TurnsSlider;
@Override
public void initialize(URL url, ResourceBundle rb) {
//Send GUI Information
movements.GetSliders(SpeedSlider, TurnsSlider);
}
}
Use a instance of the FXMLLoader
instead of the static method to get the Movements field from the controller:
Main class:
public class OpenPilot extends Application {
Movements movements;
@Override
public void start(Stage stage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader();
// use non-static load method here
Parent root = fxmlLoader.load(getClass().getResource("FXMLDocument.fxml").openStream());
// get movements from via controller
FXMLDocumentController controller = fxmlLoader.<FXMLDocumentController>getController();
movements = controller.getMovements();
Scene scene = new Scene(root);
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent Key) {
movements.GetKeys(Key);
}
});
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}