Skip to main content

Can Java Objects call JavaFX objects?

7 replies [Last post]
garywang
Offline
Joined: 2007-12-05
Points: 0

JavaFX programs can import Java classes, create new Java objects, call their methods, and implement Java interfaces.
Can Java Objects call JavaFX objects?
If I want to pass the data in a model to a Java Object, which is the best way to do this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

> Exuse me, I'v just copy your code to my project, but
> it doesnt work - java class doesn't see fx class. Are
> you shure, your code is right?

I use a command line to compile and run the samples:

> javafxc MyClass.fx
> javac Main.java
> javafx Main
[my class] test()

The solution is to compile files in the right order.

The samples are not compiled in NetBeans because of issue http://www.netbeans.org/issues/show_bug.cgi?id=133630

The NetBeans compiles java classes at first and fx files after that.
Feel free to add your comments to the issue.

sjoyner
Offline
Joined: 2007-06-13
Points: 0

I've posted some code on the wiki that shows how to pass data to a Java Object from a JavaFX script. Hope this helps.

http://jfx.wikia.com/wiki/Updating_Java_Objects_From_JavaFX_Script

megasween
Offline
Joined: 2007-11-25
Points: 0

Can you go the other way? Is it possible to set a JavaFX parameter value from Java?

pforhan
Offline
Joined: 2003-08-07
Points: 0

Look at http://jfx.wikia.com/wiki/Programmatically_invoking_a_JavaFX_Script and search for Note-1. There you will see a date object being set into the script bindings. This is available in JavaFX as now:Date or now:<>. You can put any java objects in this way.

Also relative to this discussion is http://jfx.wikia.com/wiki/Binding_to_a_POJO which uses some advanced techniques and listeners to facilitate communication between java and JavaFX.

Pat.

alexsch
Offline
Joined: 2007-07-12
Points: 0

I think that in compiler version it is possible to call JavaFX objects from java.
For example I can compile and execute the following code:
------------- MyClass.fx ------------------------------
[code]
import java.lang.System;

class MyClass{
public function test(): Void{
System.out.println("[my class] test()");
}

}
[/code]
------------- Main.java ------------------------------
[code]
public class Main {
public static void main(String[] args) {

MyClass myClass = new MyClass();
myClass.test();

}

}
[/code]
--------------------------------------------------------------

Not sure about the interpreter version.

croaker
Offline
Joined: 2008-03-30
Points: 0

Exuse me, I'v just copy your code to my project, but it doesnt work - java class doesn't see fx class. Are you shure, your code is right?

croaker
Offline
Joined: 2008-03-30
Points: 0

I'm using compiler version, certanly