Insertion trigger in JavaFX

This weekend I have written some physics equation in JavaFX like motion under gravity and collision motion. In all  complex code, we have to write a class of MotionBall, which consist attribute like X position, Y position, Velocity, Mass and Color of Ball like:

public class MotionBall extends CustomNode {

    public attribute x: Number;
    public attribute y: Number;
    public attribute velocityX: Number;
    public attribute velocityY: Number;
    public attribute mass: Number;
    public attribute radius: Number;
    public attribute color: Color;
 
    public function create(): Node {
        return Circle {
            centerX : bind x, centerY : bind y, radius : bind radius
            fill : bind color
 
        };
    }
} 

After this, the important part is to fill these data outside the class. Say, I want to make 5 instance of MotionBall. And I want to give Center X, Center Y, radius and color. Here in this code, I want to put the Balls at the random position with random radius with random color :-). Here goes the insertion trigger in JavaFX:

package insertion;

import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.geometry.Circle;
import javafx.scene.paint.Color;
import java.util.Random;


var radius: Number;
var balls: MotionBall[];

var rnd : Random = new Random();

 for( i in [1..5] ) {
                insert MotionBall {
                    x : rnd.nextInt( 170), y :  rnd.nextInt( 170 ), radius : rnd.nextInt( 10 ) + 20
                    color : Color.rgb(rnd.nextInt(255),rnd.nextInt(255),rnd.nextInt(255))
                    , opacity : 0.9
                    } into balls;
                }    
Frame {
    title: "Insertion Example"
    width: 250
    height: 250
    closeAction: function() { java.lang.System.exit( 0 ); 
    }
    visible: true

    stage: Stage {
        fill: Color.BLACK
        content: 
            bind balls
 
    }
}
 
public class MotionBall extends CustomNode {

    public attribute x: Number;
    public attribute y: Number;
    public attribute velocityX: Number;
    public attribute velocityY: Number;
    public attribute mass: Number;
    public attribute radius: Number;
    public attribute color: Color;
 
    public function create(): Node {
        return Circle {
            centerX : bind x, centerY : bind y, radius : bind radius
            fill : bind color
 
        };
    }
}

This is how output looks like : jar file.

I have written some attribute for further use, so please ignore the use.


Comments:

Excuse me, but where is the "trigger"?
i think that "trigger" would be do something else, based on the trigger it self..

as i know in the old javafx is looks like this:

trigger on insert newItem into MyClass.myAttribute
{
// do something else
}

how about the new ones?
regards.. :)

Posted by wildan on August 20, 2008 at 01:42 AM IST #

no in the new one, we need not to write trigger explicitly :) .. that's good !

Posted by Vaibhav Choudhary on August 20, 2008 at 02:42 AM IST #

Oh, i haven't know about that :(
Is it possible to cath the trigger event like the old ones? please give me an example..:)
because i still confused with the new javafx.. :)
regards..

Posted by wildan on August 20, 2008 at 04:03 AM IST #

Just wanted to say thanks for all the useful information, shifting from plain old Java to JavaFX is turning my brain into the leftovers of a horrible car accident.

Posted by chanhannigan on May 19, 2009 at 03:29 AM IST #

HI,
I am a newbee in javafx.
I want to trigger an event in my java class and catch it in javafx.
Or maybe call a javafx function from java class
Can u suggest how do I do it ?
Thanks!

Posted by erik on August 25, 2009 at 10:08 AM IST #

Post a Comment:
Comments are closed for this entry.
About

Hi, I am Vaibhav Choudhary working in Sun. This blog is all about simple concept of Java and JavaFX.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today