-
Notifications
You must be signed in to change notification settings - Fork 12
/
AnimatedCurrencyTest.java
54 lines (40 loc) · 1.64 KB
/
AnimatedCurrencyTest.java
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
package eu.iamgio.animatedtest;
import eu.iamgio.animated.binding.value.AnimatedValueLabel;
import eu.iamgio.animated.common.Curve;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.text.NumberFormat;
import java.util.Locale;
import static eu.iamgio.animatedtest.TestUtil.SCENE_HEIGHT;
import static eu.iamgio.animatedtest.TestUtil.SCENE_WIDTH;
// This demo animates the content (money) of a label.
public class AnimatedCurrencyTest extends Application {
private static final int AMOUNT_TO_ADD = 500;
@Override
public void start(Stage primaryStage) {
// Set up scene
Pane root = new Pane();
Scene scene = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
// Currency formatter
NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);
// Set up label
AnimatedValueLabel<Double> label = new AnimatedValueLabel<>(0.0)
.custom(settings -> settings.withCurve(Curve.EASE_IN_OUT_EXPO).withDuration(Duration.millis(1500)));
label.setTextMapper(formatter::format);
label.relocate(100, 100);
label.setStyle("-fx-font-size: 20");
// Set up the button
Button button = new Button("Add");
button.relocate(100, 160);
button.setOnAction(e -> label.setValue(label.getValue() + AMOUNT_TO_ADD));
root.getChildren().addAll(label, button);
// Show
primaryStage.setTitle("AnimatedCurrency");
primaryStage.setScene(scene);
primaryStage.show();
}
}