0

Learning Javascript using Eclipse PHOTON IDE and Node.js. Created JavaScript project and pasted in the example code (see below).

/**
 * http://usejsdoc.org/
 */
import javafx.stage.*;
import javafx.scene.*;
import javafx.animation.*;
import javafx.scene.effect.*;
import javafx.scene.shape.*;
import javafx.scene.input.*;
import javafx.scene.paint.*;

var balls = for(i in [0..<6]) {
    var c = Circle {
        translateX: (i*40)+90;  translateY: 30;
        radius: 18;
        fill: RadialGradient {
            focusX: 0.25;  focusY:0.25;
            proportional: true;
            stops: [
                Stop { offset: 0; color: Color.WHITE; } ,
                Stop { offset: 1; color: Color.BLACK; }
            ]
        };
    }
}

Stage {
    scene: Scene {
        content: Group {
            content: [
                Rectangle {
                    width: 380;  height: 250;  
                    opacity: 0.01;
                    onMouseClicked: 
                        function(ev:MouseEvent) { FX.exit(); }
                } , balls
            ]
            effect: Reflection {
                fraction: 0.25;  topOffset: -18;
                topOpacity: 0.5;  bottomOpacity: 0.125;
            }
        }
        fill: LinearGradient {
            endX: 0;  endY: 1;  proportional: true;
            stops: [
                Stop { offset: 0.74;  color: Color.TRANSPARENT; } ,
                Stop { offset: 0.75;  color: Color.BLACK } ,
                Stop { offset: 1;  color: Color.GRAY }
            ]
        }
    };
    style: StageStyle.TRANSPARENT
};

Timeline {
    keyFrames: for(i in [0..<sizeof balls]) {
        KeyFrame {
            time: i*200ms;
            action: function() {
                Timeline {
                    repeatCount: Timeline.INDEFINITE;
                    autoReverse: true;
                    keyFrames: [
                        at (0s) { balls[i].translateY => 30 } ,
                        at (1s) { balls[i].translateY => 230 
                            tween Interpolator.EASEIN }
                    ]
                }.play();
            }
        }
    }
}.play();

I get the following error:

C:\Users\andyh\workspace\BouncingBalls\src\BouncingBalls.js:4
import javafx.stage.*;
       ^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:236:19)

This error looks like a CLASSPATH error, but I cant figure out how to resolve it. I tried making the project nature a Java project and added JavaFX to the libraries, but that doesn't seem tp have resolved it. Any ideas. Simple test programs without JavaFX work fine.

yaccoff
  • 29
  • 4
  • 1
    Javascript and Java are completely different programming languages. JavaFX is part of Java you can't use in directly from Javascript. – greg-449 Jul 14 '18 at 12:11
  • Are you sure https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/javafx_javascript.html#BCEIBFGD – yaccoff Jul 14 '18 at 14:09
  • What have you done to make javafx callable in the project? – nitind Jul 14 '18 at 14:54
  • Nothing in that link says you can just import the javafx classes in to a Javascript program. The link is talking about communication between a JavaFX Application running in a browser and Javascript code. As of Java 9 this is all deprecated and most browsers don't support it - see [here](https://stackoverflow.com/q/19102000/2670892) – greg-449 Jul 14 '18 at 15:31
  • There may be ways to communicate between javafx and javascript. This does not mean that you can just throw some java code and some javascript code in a mixer and use both is a `.java` or a `.js` file without breaking the syntax. The functionality you're looking for here is deprecated now anyways, see https://stackoverflow.com/a/19103168/2991525 – fabian Jul 15 '18 at 02:55

0 Answers0