Skip to main content

class definition: is there this or self usable in JFX?

2 replies [Last post]
rlasjunies
Offline
Joined: 2008-06-08
Points: 0

I can not bind class attribute in the definition of another attribute of the same class or within a function of the class.

Do I miss something? ( yes;-) )

******** please help me to solve following code *********

<br />
class test {<br />
 attribute x: Integer = 0;<br />
 attribute myDouble: Integer = this.x * 2;</p>
<p> function double():Integer{<br />
   return this.x * 2;<br />
 }<br />
}<br />

*********

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rlasjunies
Offline
Joined: 2008-06-08
Points: 0

thx Shagus

shagus
Offline
Joined: 2007-05-10
Points: 0

Hi, use the bind keyword with attribute.

import java.lang.System;
class test {
attribute x: Integer = 0;
attribute myDouble: Integer = bind this.x * 2;

function double():Integer{
return this.x * 2;
}
}

var t = test{x:2 }
System.out.println("t.x value is " + t.x.toString());
System.out.println("t.myDouble value is " + t.myDouble.toString());

t.x = 5;
System.out.println("t.x value is " + t.x.toString());
System.out.println("t.myDouble value is " + t.myDouble.toString());