« 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/services/trackback/6a00e54f133d69883400e54fcc84878834

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.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

My Photo

Upcoming Speaking Engagements:


  • Stephen Chin and Jim Weaver speaking about JavaFX Platform

  • Speaking on JavaFX and Java at Øredev in Malmö, Sweden on 2-6 November, 2009

Upcoming JavaFX Training:


  • Developing Secure, Rich Internet Applications Hosted on a Variety of Clients Using JavaFX Technology

Enter your email address:

Delivered by FeedBurner

Available now as early access eBook


  • Click book image above to obtain eBook

Twitter Updates

    follow me on Twitter

    Affiliations:

    DZone Links:


    July 2009

    Sun Mon Tue Wed Thu Fri Sat
          1 2 3 4
    5 6 7 8 9 10 11
    12 13 14 15 16 17 18
    19 20 21 22 23 24 25
    26 27 28 29 30 31  

    Disclaimer:

    • By reading this site, you are agreeing that under no circumstances will Veriana Networks, Inc. or its affiliates be responsible for (1) any information contained on or omitted from the site, (2) any person's reliance on any such information, whether or not the information is correct, current or complete, (3) the consequences of any action you or any other person takes or fails to take, whether or not based on information provided by or as a result of the use of the sites.