-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathCh9_05.java
More file actions
59 lines (48 loc) · 1.92 KB
/
Copy pathCh9_05.java
File metadata and controls
59 lines (48 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import io.reactivex.Observable;
import io.reactivex.rxjavafx.observers.JavaFxObserver;
import io.reactivex.rxjavafx.schedulers.JavaFxScheduler;
import javafx.application.Application;
import javafx.beans.binding.Binding;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.util.concurrent.TimeUnit;
public final class Ch9_05 extends Application {
/*
Before running this application, make sure to do these two steps:
1) Download JavaFX SDK for your OS (from https://gluonhq.com/products/javafx/)
and unzip it in any directory.
2) Assuming you have unzipped JavaFX SDK into the folder /path/JavaFX/,
add the following options to the Java command that launches this class:
--module-path /path/JavaFX/lib
--add-modules=javafx.controls,javafx.fxml
--add-exports javafx.base/com.sun.javafx.binding=ALL-UNNAMED
If you run it from IDE, add these VM options to Run Configuration.
Use JRE 9.* to execute this example since JRE 1.8 does not have these options.
*/
public static void main(String... args) {
launch(args);
}
@Override
public void start(Stage stage) {
Pane root = new Pane();
Label label = new Label("0");
label.setScaleX(2.00);
label.setScaleY(2.00);
label.relocate(40, 40);
root.getChildren().addAll(label);
Scene scene = new Scene(root, 100, 100);
stage.setScene(scene);
stage.show();
setBinding(label);
}
private static void setBinding(Label label){
Observable<String> seconds =
Observable.interval(1, TimeUnit.SECONDS)
.map(i -> i.toString())
.observeOn(JavaFxScheduler.platform());
Binding<String> binding = JavaFxObserver.toBinding(seconds);
label.textProperty().bind(binding);
}
}