Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java bind编译但不被调用_Java_Bind_Javafx - Fatal编程技术网

Java bind编译但不被调用

Java bind编译但不被调用,java,bind,javafx,Java,Bind,Javafx,我正在尝试将打印方法绑定到xProperty()(print().bind(scene.xProperty());)。它运行一次,但当调用xProperty时,不会再次调用我的方法。我怎样才能让它不止一次地打电话 public DoubleProperty print(){ System.out.println("print"); DoubleProperty dp = new DoubleProperty(){ public void removeListene

我正在尝试将打印方法绑定到xProperty()
(print().bind(scene.xProperty());)
。它运行一次,但当调用xProperty时,不会再次调用我的方法。我怎样才能让它不止一次地打电话

public DoubleProperty print(){
    System.out.println("print");
    DoubleProperty dp = new DoubleProperty(){
        public void removeListener(ChangeListener cl){}
        public void removeListener(InvalidationListener cl){}
        public void addListener(ChangeListener cl){}
        public void addListener(InvalidationListener cl){}
        public double get(){return 10;}
        public String getName(){return "";}
        public Object getBean(){return new Object();}
        public boolean isBound(){return true;}
        public void unbind(){}
        public void bind(ObservableValue observable){}
        public void set(double d){}
    };
    return dp;

}

我不确定您在这里寻找的是什么,但我建议您使用它作为基础,而不是从头实现自己的DoubleProperty(例如,您的实现缺少对侦听器的正确处理)

例如:

public class Bean {
    private DoubleProperty print;
    public DoubleProperty printProperty(){
        if (print == null)
            print = new SimpleDoubleProperty(this, "print");
        return print;
    }
 }

现在,您可以绑定到print属性并在其上注册自己的侦听器。

您的目标是什么?是否要在场景x值发生变化时调用方法?正确。我想出了如何用一个变化的监听器来做到这一点。我想用bind代替。公共图表(向量v,场景s){super();this.v=v;s.widthProperty().addListener(新的ChangeListener(){public void已更改(Observalevalue感谢您的回复,但我不确定如何实现它,因此它将只调用一个方法。我发布的示例可能是错误的。我希望能够在调整GraphicsContext2D父场景的大小时,调用用于从画布绘制GraphicsContext2D的所有方法。