« No Need for Setters and Constructors in Compiled JavaFX Script | Main | The Future of JavaFX Script Animation: Key-Frame Animation »

December 30, 2007

Happy New Year - Formatting in Compiled JavaFX Script

I just want to wish you a Happy New Year, and to show you an example of date formatting in compiled JavaFX Script.  First, here are the screenshots of a few invocations of the program, each one taken after having changed to a different locale on my computer.  Of course, your computer is probably already set to your desired locale, so when you run this program, you should see the word "Happy", followed by the day of the week in your language, followed by the date in your language (of the first day of 2008).

Happynewyearenglishus

Happynewyearchinese

Happynewyearspanish

Happynewyeardutch

Here's the program, followed by a brief explanation of its formatting aspects:

/*
*  HappyNewYearFormatting.fx - Example of using formatting
*                              in compiled JavaFX Script
*
*  Developed 2007 by James L. Weaver (jim.weaver at lat-inc.com)
*/
import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.System;
import java.text.DateFormat;
import java.util.GregorianCalendar;
 
Frame {
  title: "Happy New Year!"
  width: 500
  height: 100
  background: Color.WHITE
  visible: true
  content:
    Canvas {
      var cal = new GregorianCalendar(2008, 0, 1)
      var df = DateFormat.getDateInstance(DateFormat.LONG)
      content:
        Text {
          font:
            Font {
              face: FontFace.SANSSERIF
              style: FontStyle.PLAIN
              size: 24
            }
          stroke: Color.RED
          fill: Color.RED
          x: 15
          y: 25
          content: bind "Happy {%tA cal}, {df.format(cal.getTime())}"
        }
    }
}

Formatting in Compiled JavaFX Script

You can control how numbers and dates are converted to character strings by providing an additional formatting prefix in a String expression. This prefix follows the specification of the Java Formatter class.  In the example above, I'm using the %tA formatting prefix to convert the date to the day of the week in the default locale.  I'm also using the capabilities of the Java DateFormat class to show the month, day and year in the language and order of the default locale.

Please have a happy, healthy, and prosperous 2008,
Jim Weaver
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
Immediate eBook (PDF) download available at the book's Apress site

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/2709996/24635724

Listed below are links to weblogs that reference Happy New Year - Formatting in Compiled JavaFX Script:

Comments

Rick,

The JavaFX compiler creates JVM bytecode in .class files, and the original FX files are not necessary for execution. Jar files are not created as a part of the javafxc process that I've referenced on this list.

You may be talking about interpreted JavaFX Script, which is just a working prototype for the compiled version, and should not be necessary too much longer.

Hello,

I was curious. I've noticed that "compiling" JavaFX script simply puts .fx files into a Java archived file (JAR).

However, anyone can go into that .jar file and see the code I wrote for the application, which may include database URL, login credentials, etc.

Aside from creating separate Java classes to grab this sensitive information, is there any way to "literally" create a jar file with some form of compiled (binary) representation of your JavaFX script files?

Any feedback would be greatly appreciated, either here or at my e-mail address.

Post a comment

If you have a TypeKey or TypePad account, please Sign In