http://java.sun.com/developer/technicalArticles/scripting/javafx/javafx_and_java/index.html
Hidden lower in the article is the first public example I see of the opposite scenario: accessing JavaFX classes from Java.
I was (naively) expecting this would be done the way Groovy does it...as real JVM classes that are interoperable across all JVM languages. But, as usual JavaFX shows its "thrown-together-in-a-hurry-as-a-response-to-Flex" roots:
public class Main {
public static void main (String[] args) {
ScriptEngineManager manager =
new ScriptEngineManager();
JavaFXScriptEngine fxEngine =
(JavaFXScriptEngine) manager.getEngineByName("javafx");
try {
String param = "JavaFX object created in Java";
String script = String.format (
"MyJavaFXClass {property: \"%s\"}", param);
Object o = fxEngine.eval(script);
fxEngine.invokeMethod(o, "printProperty");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I mean, just beautiful, isn't it...who cares about type safety and static compiling, when we just expose a half-baked scripting interface.The Silverlight/C# guys must be laughing their heads off looking at that sample.

11 comments:
Wow, indeed that is nasty. But then again, the Java platform were never about interoperability, it was about needing only one language. Hence the reason for JNI being equally, if not more, nasty.
You hit the nail on the head - Sun decided that the best way to take on Adobe would be to rush out a half-baked, Sun-only RIA solution rather than just blessing one of the dozens of open source javascript libraries out there like Dojo, jQuery, etc, etc. Just further proof that Sun still has NIH around open source.
What can I say...very disappointing. That pretty much sums it up.
Honestly, it's not that bad it's an example how JavaFX can interoperate with the 1.6 JVM Scripting support.
I honestly don't see any flex examples which do this, but at the same time why would they want to this functionality is virtually useless for most developers
How can you say that? What if I want to dynamically remove or animate certain components using Java? Will I have to stick with JavaFX as the basis of my entire application? Bad! Good way to kill Java, Sun! Steer CLEAR of JavaFX, people!
Talking about Flex? Yes you can refer to MXML components as ActionScript objects directy. But MXML sucks anyway.
JavaFX sucks also and the sooner it dies completely the better. Java offers more power and they can easily extend Java slightly so you can set an object's properties upon construction thereby making JavaFX TOTALLY redundant. e.g. Object myObject=new Object(){width:400,height:500} Although what's so difficult about putting myObject.width=400; myObject.height=500; anyway? JavaFX is truly redundant already!
Problem is Sun was trying to answer to MXML/XAML with JavaFX not realising that MXML and XAML were crappy anyway! Case in point: has anybody actually written MXML or XAML directly or just used the drag and drop window and create it automatically? Proves my point! It could just as easily have generated pure ActionScript or C#, so that you can seamlessly do operations on it! That's what we need from Sun, a WYSIWYG editor to generate pure Java. And for them to discontinue JavaFX as soon as possible! Regards, N
I'd like to revise my previous opinion. JavaFX CAN replace Java completely, and it adds some powerful and convenient features to boot. For example, bindable variables, referencing functions directly as callbacks. That means that JavaFX can make JAVA redundant, as well as the reverse being partly true. That means you don't NEED to interoperate Java and JavaFX, you can simply make the complete switch to JavaFX. Both for server and client side (I hope). It's fully object-oriented. Go JavaFX!!!!! I hope they re-name JavaFX though, because I am prepared to make the switch. Best Regards! N
Hey Navigateur, have you been hired by Sun between ur 2 posts? xD
Hi,
I tried the same example, but when I tried to run it, I got the following exception:
Exception thrown in JavaFX pretty printing: java.io.FileNotFoundException: \tmp\___FX_SCRIPT___.fxdump from StringInputBuffer.
However, if I try to eval the actual JavaFX code or put the ".fx" file as a input stream, it will work per normal, but I see exception reads:
"Exception thrown in JavaFX pretty printing: java.io.FileNotFoundException: \tmp\___FX_SCRIPT___.fxdump from StringInputBuffer (The system cannot find the path specified)"
Have you tried the example?
Dont forget that JFX is compiled to java classes, so you can just use a bit of reflection...
fxtest/Main.java:
package fxtest;
import com.sun.javafx.runtime.TypeInfo;
import com.sun.javafx.runtime.sequence.Sequence;
import com.sun.javafx.runtime.sequence.Sequences;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main {
public static void main(String[] args) {
try {
Class.forName("fxtest.FXMain").getMethod("main", Sequence.class).invoke(null, Sequences.fromArray(TypeInfo.String, args));
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
fxtest/FXMain.fx
function main(args:String[]){
FXMain{}
//... your fx code here
}
public class FXMain{
//... your fx code here
}
Oh god, blogger give a very bad indent...
You do not need any skills and more necessary rohan crone for a regular attack, but it still looks like you are using a skill. The armors and weapons which we can use our own rohan gold to buy our favorite is looking very nice. In some places you can not understand what you are doing and sometimes you did not know why and where need to spend the expensive and more rohan online crone. You can bring your own rohan money to buy Still Scroll from shop and use it on someone who you think might use bots in game. If he is confirmed to use bots later, you will get 3 equipments and some rohan online gold from him.
Post a Comment