Skip to main content

Using JavaFX Script for UI Declarations

Posted by joconner on July 20, 2007 at 8:02 PM PDT

possible javafx logoThis is an exciting time for the Java platform for a lot of reasons, and certainly JavaFX Script is part of the buzz right now. If you read much about this new script language, you'll see lots of comments about how Sun is targeting this language for rich content development, a language to help us make our UIs sparkle. I think that opportunity is real, and I think JavaFX Script can help.

At least one argument for using JavaFX Script is its simpler syntax for content developers and UI designers. Personally, I don't think the procedural, algorithmic parts of the language are that much simpler than the Java language, but I do think the declarative UI syntax is easier, or can be easier, than Java. Reading the marketing literature for the language, I think the message includes an appeal to "non-programmers" and content creators. I don't know a lot of content developers or UI designers, but I'm going to go out on a limb and say that they probably aren't that interested in packages, class definitions, for-loops, operations, and maybe not even triggers. The UI declarations and UI definitions are going to be the most interesting to to a UI designer. Seems reasonable to me anyway.

My skills and interests aren't in UI design. However, I do want to know how a Java programmer and a UI designer would work together -- one using Java for the business logic, event handlers, and models, and the other using JavaFX Script to design only the UI and maybe a little animation here and there. Maybe that's not how the language designers intended it to be used; I don't know. But that's interesting to me. And if you can't use something for an unintended purpose, what good is it? OK, maybe that's not really true for programming languages, but my kids do seem to have a lot more fun jumping on the bed than sleeping on it. I'm digressing...

Unfortunately, I haven't yet found any demos or examples that show this sort of interaction with JavaFX Script. Instead, I see great demos -- absolutely fantastic, eye-popping demos -- that launch complete applications that have been written in the new language. That's great, but I want to pull back a few notches. I don't want to create my whole application in JavaFX Script just yet; I've spent too many years as a Java programmer. I have lots and lots and lots of Java code, complete with event handlers, listeners, models, etc. Although my application UI itself might benefit from a little scrubbing and a port to JavaFX Script, I don't want to port my whole application, at least not yet. I want to introduce JavaFX Script slowly, use it for the UI view only. I want to keep all my business logic, event handlers, and models in my Java code. Now that's what I'm interested in...for now at least. And, you know what, I think that's how many Java programmers would like to use JavaFX Script right now too. Hey, that's my opinion, completely unsubstantiated of course. Let's just say it's a feeling that I have -- an unendorsed feeling completely independent from Sun Microsystems*.

So for the next few blogs, that's where I'll turn my attention. I'm not going to write a complete application in JavaFX Script, but I am going to figure out how to access a declarative UI written in the scripting language. And I'll keep all my existing business logic and models and event handlers back where I'm the Java code. I hope my exploration helps someone else too. If I'm successful, you'll know; if I'm not, you'll know that too. If you have tips and more information, share them with me as I explore this language along with you.

*[Goofy disclaimer...just in case someone thinks I actually represent Sun in my personal blogs, I do not. Nothing in this post represents official statements of Sun Microsystems, although Jonathan Schwartz does call me from time to time asking for my opinion. Wait...he doesn't sell timeshares in Vegas or refinance home loans. Hmm...maybe that wasn't him on the phone. Never mind. As it turns out, all this is still just my independent opinion. ]

Related Topics >>