Search |
||
JavaFX Doodles: Doodle #1Posted by joshy on February 6, 2008 at 5:09 PM PST
About four years ago when I started my blog I created a series of posts called Swing Hacks. This series eventually formed the basis of my similarly named book with Chris Adamson and led to my job at Sun. I think the series was successful. I still get an amazing number of hits to Swing Hacks 4, the Universal Right Click. I wish I had carried the series longer, however, since there was probably much more I could talk about. So this is why I'm starting a new series for JavaFX that I'm going to call JavaFX Doodles. Each doodle will be a small example of code snippet that does something compact but useful. I will cover only JavaFX Script initially, then add mobile and designer tools later. Also note that I am using the currently available interpreter version of the JavaFX Script syntax. I will switch to the compiler version with a slightly different syntax when it becomes available (which shouldn't be too much longer). I hope this series goes well and produces easily usable samples that will improve your own code. Let me know if there's anything you'd like to see a Doodle of. Here goes! JavaFX Doodle #1This is a simple demo I often use in my presentations. It uses basic binding and animation to create a grid of fading red cells.
Most of this code is boilerplate. It declares a subclass of Rect called Cell which adds two attributes (the JavaFX Script term for properties):
There are two interesting parts to this code which do all of the work. The first is the initializer for the The second important part is one line further down where the code sets an Whenever the mouse enters a cell it will kick off an animation for that cell. The color will go immediately to bright red and then fade back to black (since the other components of the color are already 0). That's it! These two lines do all of the hard work to create an interactive animation. LimitationsYou may have noticed a problem with this code. If you move the mouse in and out of a cell repeatedly within 5 seconds then then a new animation will start. There is no way to know if the animation is already running and optionally stop it. This is a limitation in the current animation system that is currently being overhauled by the compiler team. When the new syntax is ready I'll show you how to update to it. To try out this code just paste it into an open JavaFX Script buffer into NetBeans 6 with the latest plugin (instructions for setting up NetBeans here) Biblioteca»
Related Topics >>
Java Desktop Comments
Comments are listed in date ascending order (oldest first)
Submitted by alski on Thu, 2008-02-07 09:56.
I'm a bit baffled. If JavaFX is supposed to be some sort of "Flash killer", why is it that all the samples I ever see require me to launch JavaFxPad from Web Start. Your blog doesn't even show the sample in action, it just shows the code...is that because it's impossible at this time to get it reasonably working from a web page short of an applet of web start? The whole JavaFX experience to me feels extremely disjointed so I tend to completely ignore it. What's the real end goal for the technology?
Submitted by aberrant on Thu, 2008-02-07 10:06.
@alski Thats because its still in development. When Java 6 update N actually comes out you will see the combination of fast starting Applets, small install jvms, JavaFXScript and the scene graph and effects technology come together into something more like what you are looking for.
Submitted by raytucson on Thu, 2008-02-07 10:11.
I'm sort of with alski. I've been coding with Swing since 2001. How does a Swing programmer get started with JavaFX. Why would I switch. Should I switch. Will JavaFX have a more compelling deployment experience than WebStart. Please blog about these issues. Why would a Swing guru use JavaFX?
Submitted by mikeazzi on Thu, 2008-02-07 10:21.
Thanks Josh for the demo. I do however have a sort of unrelated question. Would you happen to have handy a JavaFX example that shows how to paint brushed metal background colors? If you do, I would really appreciate it if you could provide it.
Thanks.
Submitted by varan on Thu, 2008-02-07 11:18.
JavaFX is a lot of fun.
While porting the the Pagelayout layout manager to JavaFx I realized that JavaFx does not allow variable number of arguments to methods or functions. Is this correct? It's not a big deal, as one can always use an array of objects as an argument.
Submitted by psychostud on Thu, 2008-02-07 11:53.
Josh, I think one of the things which swing lacked was combinig animation with component behaviour ..
.i hope javafx helps us to acheive this easily...please can u show us some examples of using javafx with effects(move,fade,bounce) which are triggered on any component events like click,show,add etc term life insurance quotes
Submitted by wilsonwong on Thu, 2010-01-28 00:07.
Submitted by kishoresjava on Fri, 2008-02-08 06:00.
Any updates about the Designer Tool ?
I am eagerly waiting for the Designer Tool. can anyone know how long we may need to wait to see the Designer ?
Kishore.
Submitted by joshy on Fri, 2008-02-08 10:50.
I'm sorry I didn't respond to these questions right away. I've actually been traveling to California for meetings on JavaFX
alski: JavaFX is still very much a work in progress. Right now the NetBeans plugin is the most reliable way to run JavaFX Script code. This will change in the future as we get closer to the compiler and new runtime being released. We expect Applet support shortly as well.
raytucson: If you do Swing apps with lots of forms then FX Script likely will not impact you. FX script is for animation and graphics intensive applications, like are often done in Flash or Apple's Core Animation extensions. However, the rest of the JavaFX stack *will* affect you, like the new Applet plugin and deployment toolkit which will make getting Java installed and running both faster and easier than ever before.
mikeazzi: I'll look around for some brushed metal code and work on a blog about it.
varan: It's true that FX Script does not support varargs. I don't know if that will change. If you join the compiler mailing list you can talk to the guys working on the language itself.
psychostud I have some more demos coming that show transitions and animations. Stay tuned.
kishoresjava: The designer tool is going to take a long time to bring to 1.0. After all, Adobe's designer tools are all at least a decade old. We don't want to rush this to market. However, at JavaOne we will show you how to easily pull graphics created by designers using traditional design tools into your JavaFX applications.
Submitted by goddard on Tue, 2008-02-12 09:57.
this example doesn't run well in javafxpad. it just displays black area in which the cells should be, but they're not.
what is the best development tool for javafx? i've tried netbeans 5.5.1 with jfx plugin and opnejfx compiler. netbeans are slow for me and jfx compiler doesn't run on JRE 6. is there any plan to update javafxpad? (in case that's not continuously updated).
thanks, jiri
Submitted by joshy on Tue, 2008-02-12 10:30.
goddard: for now I recommend only running this in NetBeans 6 with the jfx plugin. We are updating JavaFX Pad to use the compiler and I *think* it will be released with the next milestone release of the compiler. When the compile and JavaFXPad are ready I will update my code to support the new animation syntax.
The complier *should* run on Java 6, though. What problems are you having?
Submitted by goddard on Tue, 2008-02-12 12:30.
joshy:
C:\Documents and Settings\Administrator>javafx
Files\Java\jdk1.6.0_02"" was unexpected at this time.
the path is not full there, but it really doesn't matter. i checked the release date and it's way old :) so i downloaded old version.
thanks for support
Term Life Quotes Life
Submitted by pjonlife on Tue, 2010-02-09 11:31.
|
||
|