Working With Java FXScript : JavaFX « Scripting « Java






Working With Java FXScript

 

import java.awt.EventQueue;
import java.io.BufferedReader;
import java.io.FileReader;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class WorkingWithJavaFXScript {
  public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    final ScriptEngine engine = manager.getEngineByName("FX");

    engine.put("msg:java.lang.String", "JavaFX Script");

    Runnable r = new Runnable() {
      public void run() {
        try {
          System.out.println("EDT running: " + EventQueue.isDispatchThread());
          engine.eval(new BufferedReader(new FileReader("demo.fx")));
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    };
    EventQueue.invokeLater(r);
  }
}
///////
// demo.fx

import javafx.ui.*;
import javafx.ui.canvas.*;
import javafx.ui.filter.*;

Frame
{
   width: 800
   height: 400
   content: Canvas
   {
      content: Text
      {
         x: 1
         y: 1
         content: "{msg:<<java.lang.String>>}"
         fill: LinearGradient
         {
            x1: 0, y1: 0, x2: 0, y2: 1

            stops: 
            [
               Stop
               {
                  offset: 0
                  color: blue
               },
            ]
         }

         filter: [MotionBlur { distance: 10.5 }, Glow {amount: 0.15},
                  Noise {monochrome: false, distribution: 0}]
      }
   }
   visible: true
}


 








Related examples in the same category