本文整理汇总了Java中javafx.beans.binding.DoubleBinding.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleBinding.addListener方法的具体用法?Java DoubleBinding.addListener怎么用?Java DoubleBinding.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.beans.binding.DoubleBinding
的用法示例。
在下文中一共展示了DoubleBinding.addListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: StraightEdgeView
import javafx.beans.binding.DoubleBinding; //导入方法依赖的package包/类
public StraightEdgeView(DoubleProperty sX, DoubleProperty sY, DoubleProperty eX, DoubleProperty eY) {
super(sX, sY, eX, eY);
aX = new DoubleBinding() {
{
super.bind(sX, eX);
}
@Override
protected double computeValue() {
return (sX.get() + eX.get()) * .5;
}
};
aY = new DoubleBinding() {
{
super.bind(sY, eY);
}
@Override
protected double computeValue() {
return (sY.get() + eY.get()) * .5;
}
};
Line line = new Line();
line.setStrokeWidth(1.5);
line.setStroke(Color.BLUE);
line.startXProperty().bind(sX);
line.startYProperty().bind(sY);
line.endXProperty().bind(eX);
line.endYProperty().bind(eY);
Polygon arrow = new Polygon();
arrow.setFill(Color.BLUE);
final ChangeListener<Number> listener = (_0, _1, _2) -> {
final double angle = a.get() + Math.PI;
final double x = aX.get();
final double y = aY.get();
final double x0 = x + 5 * Math.cos(angle);
final double x1 = x + 5 * Math.cos(angle + 2 * Math.PI / 3);
final double x2 = x + 5 * Math.cos(angle - 2 * Math.PI / 3);
final double y0 = y + 5 * Math.sin(angle);
final double y1 = y + 5 * Math.sin(angle + 2 * Math.PI / 3);
final double y2 = y + 5 * Math.sin(angle - 2 * Math.PI / 3);
arrow.getPoints().clear();
arrow.getPoints().addAll(x0, y0, x1, y1, x2, y2);
};
aX.addListener(listener);
aY.addListener(listener);
getChildren().addAll(line, arrow);
}
示例2: BidirectionalDoubleOffsetBinding
import javafx.beans.binding.DoubleBinding; //导入方法依赖的package包/类
private BidirectionalDoubleOffsetBinding(DoubleProperty property1, DoubleProperty property2, DoubleBinding offset) {
this.offset = offset;
this.lhs = property1;
this.rhs = property2;
lhs.set(rhs.get() + offset.get());
rhs.addListener(this);
lhs.addListener(this);
offset.addListener(this);
}