Forum Stats

  • 3,840,360 Users
  • 2,262,592 Discussions
  • 7,901,243 Comments

Discussions

Question about bindings on JavaFX 2.0

865172
865172 Member Posts: 34
edited May 28, 2011 7:37PM in JavaFX 2.0 and Later
Hi, i'm playing a little with the beta version, and testing experiments done on 1.3 migrating them.
Then,
on JavaFX 1.3 had this simple variable definition with bindings for an object to move:

public var velocity : Number;
public var angle : Number;
public var vx : Number = bind velocity*Math.cos(angle);
public var vy : Number = bind velocity*Math.sin(angle);

Now, with JavaFX 2.0 i'm a little confiused on how to do the same thing??
some suggestion?
Thanks.

Answers

  • darrylburke
    darrylburke Member Posts: 18,007
    http://download.oracle.com/javafx/2.0/binding/jfxpub-binding.htm

    Bookmark this page: http://download.oracle.com/javafx/

    db
    darrylburke
  • 865172
    865172 Member Posts: 34
    edited May 28, 2011 7:37PM
    I improved that with:


    private DoubleProperty velocity = new DoubleProperty();
    private DoubleProperty angle = new DoubleProperty();
    private double vx;
    private double vy;

    private ChangeListener vListener = new ChangeListener()
    {
    @Override public void changed(ObservableValue o,Object oldVal,Object newVal)
    {
    vx = velocity.get()*Math.cos(angle.get());
    vy = velocity.get()*Math.sin(angle.get());
    }
    };

    ...

    velocity.addListener(vListener);
    angle.addListener(vListener);


    It works fine. Thanks.

    Edited by: user1753070 on 28-may-2011 16:37
This discussion has been closed.