Skip to main content

Reflect the clock

Posted by malenkov on March 3, 2009 at 10:00 AM PST

This application creates a digital clock, and is based on the analog clock implementation taken from another example. String formatting is applied to display the current time. Unfortunately, the application can not be run on the mobile emulator, because the mobile profile of JavaFX API does not support graphical effects yet.

I'm a little bit lazy today. Therefore, I borrowed the implementation of the application and clock widget from my first post about JavaFX, and made just a few changes to the clock widget overriding only the create method. The diff-file is available.

  override function create() {
    try {
      def name = "javafx.scene.effect.Reflection";
      effect = Class.forName(name).newInstance() as Effect
    catch (exception) {
    def font = bind Font {
      size: radius / 3
    Text {
      stroke:     bind stroke
      fill:       bind fill
      font:       bind font
      translateY: bind font.size
      content:    bind "{%02d calendar.get(Calendar.HOUR)}:"
                       "{%02d calendar.get(Calendar.MINUTE)}:"
                       "{%02d calendar.get(Calendar.SECOND)}"

Note that the %02d template is used for string formatting. This template implies that an integer value is presented in the decimal form, and has a length no less than two symbols. Zero-padding is used to align elements.

If you comment out the code lines that use effects and run the application on emulator, string formatting will not work properly.

original post

Related Topics >>


The %TT template is shorter: content:bind "{%TT calendar}" but it does not work on mobile emulator at all...