As I mentioned in my post on the Learning JavaFX weblog a week ago, this JavaFX Puzzler will require writing a compiled JavaFX Script program. In subsequent posts on that weblog, I've provided instructions for using the OpenJFX Compiler to compile a JavaFX Script program into Java bytecode, and to run the program. If you haven't seen these posts, please review them.
The first person to post a comment with a correct solution will be given a free JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications eBook (PDF download). When submitting your answer, be sure to put your correct email address in the "Email Address: (Not displayed with comment.)" text field on the comment form so that I can contact you with the information to obtain your free eBook.
Requirements for Puzzler 4: The Puzzler4Compiled Program
Here is the console output of the sample solution:
changingText was replaced with Hello
The requirements for this program are as follows:
- The console output must be the same as shown above
- The program must define a class named Puzzler4Compiled that has an attribute named changingText that is of type String.
- The changingText attribute must have an on replace trigger that prints "changingText was replaced with" followed by the new value of the changingText attribute.
- An instance of the Puzzler4Compiled class must be created, setting the value of the changingText attribute to "Hello". This causes the trigger to be executed, and the output shown above to be printed on the console.
Enjoy!
Jim Weaver
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
Immediate eBook (PDF) download available at the book's Apress site
Hi Jim, here is the "compiled" version.
import java.lang.*;
class Puzzler4Compiled {
attribute changingText: String = "changingText was replaced with" on replace { System.out.println( changingText ); };
}
var example = Puzzler4Compiled {};
example.changingText = "Hello";
Posted by: Shakir Gusaroff | November 28, 2007 at 07:18 PM
Shakir,
This JavaFX Puzzler requires writing a *compiled* JavaFX Script program (see the first sentence of this post). Please see the following post for details on how to obtain the JavaFX compiler in its current form: http://learnjavafx.typepad.com/weblog/2007/11/compiler-cheat.html
Other recent posts cover some of the syntax changes for the compiled version.
Thanks,
Jim Weaver
Posted by: Jim Weaver | November 28, 2007 at 03:17 PM
import java.lang.*;
class Puzzler4Compiled {
attribute changingText:String;
}
trigger on Puzzler4Compiled.changingText[oldValue] = newValue {
System.out.println( "{oldValue} {newValue}" ) ;
}
var x = Puzzler4Compiled {changingText:"changingText was replaced with" };
x.changingText = "Hello";
Posted by: Shakir Gusaroff | November 28, 2007 at 02:59 PM