天下

记录修行的印记

JavaFX PropertyTest2

package application.chapter2;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ObservableValue;

public class PropertyTest2 {

    public static void main(String[] args) {
        IntegerProperty counter = new SimpleIntegerProperty(100);
        // Add an invalidation listener to the counter property
        counter.addListener(PropertyTest2::changed);
        System.out.println("Before changing the counter value-1");
        counter.set(101);
        System.out.println("After changing the counter value-1");
        /*
         * At this point counter property is invalid and further changes to its value
         * will not generate invalidation events.
         
*/
        System.out.println("\nBefore changing the counter value-2");
        counter.set(102);
        System.out.println("After changing the counter value-2");
        // Make the counter property valid by calling its get() method
        int value = counter.get();
        System.out.println("Counter value = " + value);
        /*
         * At this point counter property is valid and further changes to its value will
         * generate invalidation events.
         
*/
        // Try to set the same value
        System.out.println("\nBefore changing the counter value-3");
        counter.set(102);
        System.out.println("After changing the counter value-3");
        // Try to set a different value
        System.out.println("\nBefore changing the counter value-4");
        counter.set(103);
        System.out.println("After changing the counter value-4");
    }

    public static void changed(ObservableValue<? extends Number> prop,Number oldValue,Number newValue) {
        System.out.print("Counter changed: ");
        System.out.println("Old = " + oldValue + ", new = " + newValue);
    }
}

posted on 2020-01-01 13:19 天下 阅读(275) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2020年1月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(4)

随笔分类(378)

随笔档案(329)

链接

最新随笔

搜索

最新评论