All the Interesting ThingsThis is a personal web log. All information posted here does not represent my employer. I do not speak for my employer. |
|
Saturday May 16, 2009
Five Articles on JavaFX Pac-Man Game
Posted at 09:23AM May 16, 2009 by morningstar in JavaFX |
Thursday May 14, 2009
My Articles on Writing the Pac-Man Game in JavaFX
After I wrote the Pac-Man game with JavaFX, many people were asking me to give more details on writing the game. JavaFX guru Jim Weaver had invited me to write some articles on the game. Now, with Jim's help, our articles are featured on O'Reilly's insiderRIA.com . Here is the link to the articles: Writing the Pac-Man Game in JavaFX Posted at 08:51PM May 14, 2009 by morningstar in JavaFX | Comments[1]
Friday Jan 02, 2009
JavaFX技术中文博客
新年伊始,趁着假期,把几篇英文的JavaFX博文翻译了一下,以后争取中英两种语言一起发吧,可以参考这里:
javaFX guy的博客 教程 例子示范游戏 学习 编程 Posted at 08:34AM Jan 02, 2009 by morningstar in JavaFX |
Friday Dec 26, 2008
Interoperability between JavaFX and Java The JavaFX blog has an article which discussed the possiblity of a SWING application to invoke methods of JavaFX classes from Java code. Right now, JavaFX can call Java code without any problem, however, the reverse is not supported by JavaFX. Doing some googling shows that programmers are trying all kinds of hacks to invoke a JavaFX class method from Java. You can check out an interesting article on reverse engineering of JavaFX classes. Even the example on JavaFX blog provided a hack to work around this. So do we have the need of such kind of interaction between Java and JavaFX? I vote it for "YES". If Java and JavaFX can be used interchangeably (when possible), this could give more life to JavaFX in the long run. Just consider the MVC design pattern, we can write an application by using Java and JavaFX together. The "M" and "C" part can be implemented in Java while the "V" can be done by JavaFX. It would be very interesting to see this. Right now, there are a few "standard" ways to call JavaFX from Java: 1) Using the ScriptEngineManager class. From Geertjan Wielenga's article, we can do it in this way: package calc;
import java.io.InputStreamReader;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class CalculatorLauncher {
public static void main(String[] args) {
try {
ScriptEngineManager manager=new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("fx");
InputStreamReader reader = new InputStreamReader
(CalculatorLauncher.class.getResourceAsStream
("Calculator.fx"));
engine.eval(reader);
} catch (ScriptException ex) {
}
}
}
However, this is just like System.exec("calc") as pointed out by cronseaux. I agree with him. A even simpler way is to use System.exec("javafx Calculator.fx") to complete the above code. So this is not a good solution.
2) Manage to use java reflection to call JavaFX class methods. This one should work because JavaFX classes are compiled into Java classes and byte code. However, the complexity makes it almost unusable and code written in this way has no readability. 3) A third approach is to define an interface in Java and implement it in JavaFX. For example,
public interface JavaInterface
{ ... }
In MyJavaFXClass.fx, do something like:
public class MyJavaFXClass extends JavaInterface
{ ... }
In you java code, just invoke the JavaFX object directly using the interface. This approach can solve most of the interoperation issues. Just that an interface is needed for every JavaFX class which is going to be called from Java. Though it is very cumbersome, at least it is the best workaround I can find so far.
Since this is the first release of JavaFX, I don't criticize much on this given the strong powerful features of JavaFX. I do hope the future releases of JavaFX can improve on this.
Posted at 07:21AM Dec 26, 2008 by morningstar in JavaFX | Comments[2]
Monday Dec 08, 2008
My First JavaFX Game: PAC MAN (updated example) I updated my JavaFX PACMAN game with some features today:
1) The ghosts can run away from the pacman after the pacman eats the magic bean.
Right now, 85% of the game is completed. Things to do:
JRE 1.5+ required, JRE1.6 U10 is better, click on the below image or button to start playing, or watch it on Youtube:
If you cannot play now, you can watch the video:
Posted at 07:39AM Dec 08, 2008 by morningstar in JavaFX | Comments[19] |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||