Menu Pilihan:
iToonTV Cartoon
(6)
iToonTV Comic
(2)
iToonTV Game
(3)
iToonTV Music
(2)
iToonTV News
(18)
iToonTV Shorts
(4)
JavaFX Tips and Tricks: Invoking JavaFX Functions from Java
Occasionally the requirement arises to call a JavaFX function from within a Java method. I needed to do this yesterday, so I thought I'd take a moment to explain a way to do this in three simple steps:- Create a Java interface
- Extend the interface with a JavaFX class, implementing any functions defined by the interface
- Obtain a reference to, and call a function of, the JavaFX class defined by the interface
Here are snippets of the code that I created yesterday in the context of the steps listed above:
Create the Java interface
public interface UniverseHandler {
public void onSphereClicked(SphereBranch sphereBranch);
}
Extend the interface with a JavaFX class, implementing any functions defined by the interface
public class WindshieldModel extends UniverseHandler {
...model code omitted...
/**
* This is called when user clicks a sphere on the 3D Canvas
*/
public override function onSphereClicked(sphereBranch:SphereBranch) {
curSphereBranch = sphereBranch;
}
}
Obtain a reference to, and call a function of, the JavaFX class defined by the interface
universeHandler.onSphereClicked(currentSphereBranch);
The universeHandler was passed into the constructor of the Java class.
Thanks again to InteractiveMesh.org for their lightweight 3D canvas and classes that enable JavaFX/Java 3D integration!
Subscribe to:
Post Comments (Atom)
Yang Sering Dibaca:
-
Anda pengguna aktif Facebook? Ada kabar baru datang dari website jejaring sosial yang sedang banyak digandrungi oleh pengguna internet dunia...
-
On the morning of 8.1, the management company of actor Lee Min Ho revealed he was hospitalized following treatment falling water scenes in...
0 comments: