Skip to content

Instantly share code, notes, and snippets.

@YSRKEN
Last active April 11, 2018 09:48
Show Gist options
  • Save YSRKEN/1fbaf12fd0c55e07434661a2e7469ad2 to your computer and use it in GitHub Desktop.
Save YSRKEN/1fbaf12fd0c55e07434661a2e7469ad2 to your computer and use it in GitHub Desktop.
Java+JavaFX+MVVMでストップウォッチアプリを作成してみた所感 ref: https://qiita.com/YSRKEN/items/d926ac60a25e3168db7a
// 本家が勧めてくる「高レベル・バインディングAPI」とやら
IntegerProperty num1 = new SimpleIntegerProperty(1);
IntegerProperty num2 = new SimpleIntegerProperty(2);
IntegerProperty num3 = new SimpleIntegerProperty(3);
IntegerProperty num4 = new SimpleIntegerProperty(4);
NumberBinding total =
Bindings.add(num1.multiply(num2),num3.multiply(num4));
System.out.println(total.getValue());
// こう書いた方が可読性が高いのでは??
IntegerProperty num1 = new SimpleIntegerProperty(1);
IntegerProperty num2 = new SimpleIntegerProperty(2);
IntegerProperty num3 = new SimpleIntegerProperty(3);
IntegerProperty num4 = new SimpleIntegerProperty(4);
int total;
Runnable runner = () -> {
total = num1.get() * num2.get() + num3.get() * num4.get();
};
num1.addListener((ob, oldVal, newVal) -> setTotal());
num2.addListener((ob, oldVal, newVal) -> setTotal());
num3.addListener((ob, oldVal, newVal) -> setTotal());
num4.addListener((ob, oldVal, newVal) -> setTotal());
System.out.println(total);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment