JavaFX Demo Code

Posted: August 13th, 2008 under JavaFX, Others.
Tags: ,

Got a JavaFX Demo Code from Josh Marinacci, a key JavaFX team member. From this demo, we can see the source code is very succinct. I did some Java Swing programming before, so I understand this means the tremendous effort savings in user interface implementation.

import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;
import javafx.application.*;
import javafx.scene.transform.*;
import javafx.input.*;
import javafx.animation.*;
import java.lang.System;

var angle = 0.0;

Frame {
    windowStyle: WindowStyle.TRANSPARENT  visible: true
    width: 400 height: 400
    stage: Stage {
        fill: null
        content: Group {
            translateX: 100 translateY: 100
            content: for(i in [0..10]) {
              // here is the magic with binding
              Rectangle {
                fill: Color.rgb(25*i,0,0, i/10.0)
                width: 100
                height: 100
                arcHeight: 10 arcWidth: 10
                stroke: Color.BLACK strokeWidth: 5
                transform: bind [
                  Transform.rotate(-i*36+angle/2,50,50),
                  Transform.translate(angle/4,0),
                 ]
               }
            }
          onMousePressed:
           function(e:MouseEvent):Void
           { System.exit(0); }
        }
    }
}

var anim = Timeline { keyFrames: [
   KeyFrame { time: 0s
    values: angle => -360 tween Interpolator.EASEBOTH },
   KeyFrame { time: 2s
    values: angle => 360 tween Interpolator.EASEBOTH },
    ]
   autoReverse: true
   repeatCount: Timeline.INDEFINITE
};
anim.start();

Though I do not fully understand the code, it seems to me it is a simple way to things we used to spend tons of work. Currently, the CPU usage is a bit higer, so I think they can improve it when the final release comes out.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL