我试图将我的打印方法绑定到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;
}
你的目标是什么?你想调用一个有史以来场景x值改变的方法吗? – invariant
正确。我想出了如何用变化监听器来做到这一点。我想用bind来代替。 \t public chart(Vector v,Scene s){ \t \t super(); \t \t this.v = v; \t \t s.widthProperty()。的addListener(新的ChangeListener (){ \t \t \t公共无效改变(ObservableValue <?延伸号码> OV, \t \t \t号old_val,编号new_val){ \t \t \t \t平局(); \t \t \t} \t \t}); \t} –
user1958884