« January 2009 »
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
21
22
24
25
27
28
       
       
Today
XML

Blog::Navigation

GetJava Download Button
Get the Source
Personal Blog

Blog::Referers

Today's Page Hits: 47

Powered by Roller Weblogger.
« Previous month (Dec 2008) | Main | Next month (Feb 2009) »
20090226 Thursday February 26, 2009

Prizes for having fun! Hurry....

Do you live in India? What do you want? Sony Ericsson phone or Canon Camera or iPod? If so, have fun writing JavaFX code and win any of these prizes!



( Feb 26 2009, 08:16:59 PM IST ) Permalink del.icio.us | furl | simpy | slashdot | technorati | digg

20090223 Monday February 23, 2009

JavaFX interactive shell

JavaFX compiler has a built-in script shell - Per Bothner has implemented a read-eval-print loop facility for JavaFX. The script shell class is com.sun.tools.javafx.script.ScriptShell. Note:This is in the openjfx-compiler repository and not in the JavaFX 1.0 binary.

A sample JavaFX session is as follows:


$ java -cp dist/lib/shared/javafxc.jar com.sun.tools.javafx.script.ScriptShell 
/*fx1*/ "hello"
hello
/*fx2*/ 2 + 4
6
/*fx3*/ function greet (name) { println("Hello, {name}") }
/*fx4*/ greet("Sundar")
Hello, Sundar
/*fx5*/ var s = [ "Sunday", "Monday", "Tuesday" ]
[ Sunday, Monday, Tuesday ]
/*fx6*/ for (i in s) println(i) 
Sunday
Monday
Tuesday
/*fx7*/ class Person { public var name: String; }               
/*fx8*/ var p = Person { name: "Sundar" }
fx7$Person@13fba1
/*fx9*/ p.name
Sundar
/*fx10*/ import javax.swing.*;
/*fx11*/ var f = new JFrame("hello");
fx11:1: cannot find symbol
symbol  : class JFrame
location: class fx11
/*fx12*/   
/*fx13*/ var f = new javax.swing.JFrame("hello")
javax.swing.JFrame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=hello,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
/*fx14*/ f.setSize(300, 300)
/*fx15*/ f.setVisible(true)

While there is a generic shell called "jrunscript" for languages that implement jsr-223, it does not work very well for statically typed languages (which can be said about jsr-223 itself). But, the above mentioned JavaFX script shell is independent of jsr-223 interface.

Besides, jrunscript crashes for JavaFX!


$ jrunscript -cp dist/lib/shared/javafxc.jar -l javafx
fx> "hello"
Exception in thread "main" java.lang.NoSuchMethodError: com.sun.tools.javac.main.RecognizedOptions.getJavacFileManagerOptions(Lcom/sun/tools/javac/main/RecognizedOptions$OptionHelper;)[Lcom/sun/tools/javac/main/JavacOption$Option;
	at com.sun.tools.javac.util.JavacFileManager.(JavacFileManager.java:973)
	at com.sun.tools.javafx.api.JavafxcTool.getStandardFileManager(JavafxcTool.java:102)
	at com.sun.tools.javafx.script.JavaFXScriptCompiler.(JavaFXScriptCompiler.java:87)
	at com.sun.tools.javafx.script.JavaFXScriptContext.(JavaFXScriptContext.java:45)
	at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.getJavaFXScriptContext(JavaFXScriptEngineImpl.java:61)
	at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.getJavaFXScriptContext(JavaFXScriptEngineImpl.java:55)
	at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.parse(JavaFXScriptEngineImpl.java:220)
	at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:173)
	at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:164)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
	at com.sun.tools.script.shell.Main.evaluateString(Main.java:280)
	at com.sun.tools.script.shell.Main.processSource(Main.java:249)
	at com.sun.tools.script.shell.Main.access$100(Main.java:19)
	at com.sun.tools.script.shell.Main$1.run(Main.java:165)
	at com.sun.tools.script.shell.Main.main(Main.java:30)

This is because JavaFX compiler code depends on modified javac classes. The code for jrunscript lives in tools.jar along with the unmodified javac classes! These unmodified javac classes are loaded which results in exception from javafxc code! We have to use the bootstrap path workaround as shown below:


$ jrunscript -J-Xbootclasspath/p:./dist/lib/shared/javafxc.jar -l javafx
fx> 233 + 334
567
fx> for (i in [0..4]) println(i)
0
1
2
3
4
fx> 

But, now we have a much better ScriptShell for JavaFX :-) We don't need to resort to this hack...



( Feb 23 2009, 01:12:28 PM IST ) Permalink Comments [4] del.icio.us | furl | simpy | slashdot | technorati | digg

20090220 Friday February 20, 2009

A JavaFX compiler debug trick

There is an unsupported (read - can be removed in future without notice!) command line option with JavaFX compiler. If you run javafxc as


    javafxc -XDdumpjava Test.fx

the compiler generates intermediate Java code for your JavaFX program in "./dumpjava" directory (compiler expects you to create ./dumpjava directory before invoking javafxc). This is meant to be a debugging option for JavaFX compiler developers. But, you can look at generated Java code to see what happens behind the scenes - much like C++ programmers used to look at intermediate C code and/or preprocessed code.



( Feb 20 2009, 12:14:08 PM IST ) Permalink Comments [1] del.icio.us | furl | simpy | slashdot | technorati | digg

JavaFX for Java, JavaScript programmers

I missed attending and speaking at Sun Tech Days at Hyderabad due to a personal reason :-( In fact, I prepared slides for a talk titled "JavaFX for Java, JavaScript programmers". This is much like my earlier language comparison blog entries such as Java, JavaScript and Jython, Java, Groovy and JRuby etc. The idea is to learn a language by language comparison - and not to conclude "better"/"worse" language and so on. So, no politics please :-) Although I could not attend Sun Tech Days, I am posting the slides here : slides in a .pdf file



( Feb 20 2009, 12:06:00 PM IST ) Permalink Comments [3] del.icio.us | furl | simpy | slashdot | technorati | digg

Copyright (C) 2005, A. Sundararajan's Weblog