Created
May 15, 2019 09:18
-
-
Save rikmeijer/147e65d8a4ba330d3578a06ecf09c6e8 to your computer and use it in GitHub Desktop.
PROG4_Wk4b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package PROG4_WK4b; | |
| import javafx.application.Application; | |
| import javafx.concurrent.Task; | |
| import javafx.scene.Scene; | |
| import javafx.scene.control.ProgressBar; | |
| import javafx.scene.layout.BorderPane; | |
| import javafx.stage.Stage; | |
| public class Main extends Application { | |
| @Override | |
| public void start(Stage primaryStage) { | |
| try { | |
| Task<Void> task = new Task<Void>() { | |
| @Override public Void call() throws InterruptedException { | |
| for (int i=0; i<=100; i+=10) { | |
| updateProgress(i, 100); | |
| Thread.sleep(1000); | |
| } | |
| return null; | |
| } | |
| }; | |
| ProgressBar bar = new ProgressBar(); | |
| bar.progressProperty().bind(task.progressProperty()); | |
| bar.setMinWidth(800); | |
| bar.setMinHeight(200); | |
| new Thread(task).start(); | |
| BorderPane pane = new BorderPane(); | |
| pane.setMinWidth(400); | |
| pane.setMinHeight(300); | |
| pane.setCenter(bar); | |
| Scene scene = new Scene(pane); | |
| primaryStage.setScene(scene); | |
| primaryStage.show(); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| public static void main(String[] args) { | |
| launch(args); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/18880455/task-vs-service-for-database-operations