Example usage for javafx.beans.property SimpleIntegerProperty addListener

List of usage examples for javafx.beans.property SimpleIntegerProperty addListener

Introduction

In this page you can find the example usage for javafx.beans.property SimpleIntegerProperty addListener.

Prototype

@Override
    public void addListener(InvalidationListener listener) 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    SimpleIntegerProperty xProperty = new SimpleIntegerProperty(0);

    // Adding a change listener with anonymous inner class
    xProperty.addListener(new ChangeListener<Number>() {
        @Override/*  w w  w  .ja va2s  .  c  o m*/
        public void changed(ObservableValue<? extends Number> ov, Number oldVal, Number newVal) {
            System.out.println("old value:" + oldVal);
            System.out.println("new value:" + newVal);
        }
    });

    // Adding a change listener with lambda expression
    xProperty.addListener((ObservableValue<? extends Number> ov, Number oldVal, Number newVal) -> {
        System.out.println("old value:" + oldVal);
        System.out.println("new value:" + newVal);
    });
}

From source file:Main.java

public static void main(String[] args) {
        SimpleIntegerProperty xProperty = new SimpleIntegerProperty(0);

        // Adding a invalidation listener (anonymous inner class)
        xProperty.addListener(new InvalidationListener() {
            @Override/*  ww  w. j  a  v  a 2s  . com*/
            public void invalidated(Observable o) {
                System.out.println(o.toString());
            }
        });

        // Adding a invalidation listener (lambda expression)
        xProperty.addListener((Observable o) -> {
            System.out.println(o.toString());
        });

    }