List of usage examples for javafx.concurrent Task valueProperty
@Override public final ReadOnlyObjectProperty<V> valueProperty()
From source file:employees.Employees.java
@Override public void start(Stage stage) throws Exception { // Parent root = FXMLLoader.load(getClass().getResource("MainUI.fxml")); // /*from w ww . j av a 2 s . c o m*/ // Scene scene = new Scene(root); // // stage.setScene(scene); // stage.show(); //new LoginStage(); Task<String> inittask = inittasks.pingServer(); StringProperty pingResponse = new SimpleStringProperty(); StringProperty messages = new SimpleStringProperty(); pingResponse.bind(inittask.valueProperty()); messages.bind(inittask.messageProperty()); inittask.stateProperty().addListener((workerState, oldState, newState) -> { if (newState == Worker.State.SUCCEEDED) { String response = pingResponse.get(); JSONObject obj = new JSONObject(response); String Status = obj.getString("Status"); if (Status.equals("OK")) { AlertDialog ad = new AlertDialog(); ad.showDialog(AlertTypes.Types.INFORMATION, "Successfull", "PING OK", "Connection Successfull"); } } else if (newState == Worker.State.CANCELLED) { AlertDialog ad = new AlertDialog(); ad.showDialog(AlertTypes.Types.WARNING, "Operation Aborted", "Operation Aborted", "Task Was Cancelled,The System Will Now Exit"); System.exit(0); } else if (newState == Worker.State.FAILED) { StringBuilder errstr = new StringBuilder(); errstr.append( "An Error Has Occured While Connecting to The Server, A Description of the Error is Shown Below : \n"); errstr.append(messages.toString()); AlertDialog ad = new AlertDialog(); ad.showDialog(AlertTypes.Types.ERROR, "An Error Occurred While Connecting to The Server", "Error", messages.get()); Optional<ButtonType> response = AlertDialog.showConfirmation( "Unable to Connect to The Server: Would you Like To Review Your Network Settings?", "Connection Settings Review", "Review Connection Settings?"); if (response.get() == ButtonType.OK) { try { new initSettingsStage(); } catch (IOException ex) { Logger.getLogger(Employees.class.getName()).log(Level.SEVERE, null, ex); } } } }); new Thread(inittask).start(); }