2013-10-06 66 views
0

我有一個DoubleProperty(price),我想要第二個DoubleProperty(discountedPrice)綁定到price - 25%如何將DoubleProperty綁定到表達式?

所以我想我會用multiply方法,但它似乎並不如預期的工作:

DoubleProperty price = new SimpleDoubleProperty(); 
DoubleProperty pctDiscount = new SimpleDoubleProperty(); 
pctDiscount.bind(price.multiply(0.75)); 

price.set(100); 

System.out.println(pctDiscount); 

我期待的節目輸出75,但輸出是:

DoubleProperty [bound,invalid]

回答

4

DoubleProperty是一個包裝類。要獲得實際值

System.out.println(pctDiscount.getValue()); 

System.out.println(pctDiscount.get()); 
相關問題