Skip to main content

Call/run an interpreted JFX custom node class

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

Hi all,

Is it possible to have an interpreted JFX class called from a compiled JFX application?

In fact what I would like to do is:
* read a file within a customnode class
* interprete this class
* add the Node in an canvas

Thank to give me a good answer or/and the good links ;-)

R

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

I found an example here ... but I've an error message.
http://blogs.sun.com/michaelheinrichs/entry/using_javafx_objects_in_java

My code create (should;-) a CustomNode ... boom ... \tmp\___FX_SCRIPT___.fxdump

Help ... :-)

[code]
var oNode : Node;
var manager: ScriptEngineManager = ScriptEngineManager{};
var fxEngine: JavaFXScriptEngine = manager.getEngineByName("javafx") as JavaFXScriptEngine;
System.out.println("Number of elements:{sizeof Elts}");

try {
oNode = fxEngine.eval(
"import javafx.scene.geometry.*;"+
"import javafx.scene.CustomNode;"+
"import javafx.scene.Group;"+
"import javafx.scene.Node;"+
"import javafx.scene.paint.*;"+
""+
"public class myRect extends CustomNode \{"+
" public function create(): Node \{"+
" return Group \{"+
" content: [ Rectangle\{"+
" x:100;y:100;width:100;height:100 "+
" }]"+
" };"+
" }" +
"}") as Node;
} catch (e:Exception){
e.printStackTrace();
}
System.out.println("Number of elements:{sizeof Elts}");
insert oNode into Elts;
System.out.println("Number of elements:{sizeof Elts}");
[/code]

********** output *************
Number of elements:0
Exception thrown in JavaFX pretty printing: java.io.FileNotFoundException: \tmp\___FX_SCRIPT___.fxdump from StringInputBuffer (Le chemin d'accès spécifié est introuvable)
Number of elements:0
Number of elements:0

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

Sorry, the article is old and I do not find the time to check, if the examples are still working. *blush*

I will try as soon as possible.

rlasjunies
Offline
Joined: 2008-06-08
Points: 0

Thank you Michael,

If found an issue in my sample. I've reworked it and now I've something that satisfied me. Here it's the code.

Thank again.

/********************************************************
[code]
package framescripting;

import java.lang.*;
import javax.script.ScriptEngineManager;
import com.sun.javafx.api.JavaFXScriptEngine;
import javafx.application.*;

var manager: ScriptEngineManager = ScriptEngineManager{};
var fxEngine: JavaFXScriptEngine = manager.getEngineByName("javafx") as JavaFXScriptEngine;

function oScriptingStage():Stage{
var oNode : Stage;
try {
oNode = fxEngine.eval(
"import javafx.application.*; \n"+
"import javafx.scene.paint.Color; \n"+
"import javafx.scene.geometry.*;"+
" \n"+
"Stage\{"+
" height: 200 " +
" width: 200 " +
" fill: Color.GREEN"+
" content: Circle\{"+
" centerX: 10 " +
" centerY: 10" +
" radius: 10" +
" }" +
"}" as String ) as Stage;

} catch (e:Exception){
e.printStackTrace();
System.out.println("Exception during scripting call");
}
return oNode
}

Frame{
title: "scripting object"
stage: oScriptingStage()
visible: true
}
[/code]