Timelineを用いて1秒ごとに時刻を表示するプログラム

JRubyFXによるアニメーションを調べていて、まずは簡単なところから始めてみようと思う。
テキスト(ラベル)を1秒ごとに更新するプログラムを作成してみた。
Timelineに登録されたハンドラを1000msごとに呼ぶという単純なプログラムになっている。

require 'jrubyfx'

class Hello < JRubyFX::Application
  def start(stage)
    @stage = stage
    with(stage,title: "sample",width: 200,height: 100) do
      tt = nil
      layout_scene do
        stack_pane do
          label("", id: 'view' )
        end
      end
      show
    end
    play
  end

  def refresh_time
    t = Time.now
    #puts t
    @stage['#view'].text = t.to_s
  end

  def play
    refresh_time
    handler = EventHandler.impl {|n,e| refresh_time}
    time = Timeline.new
    time.cycle_count = :indefinite
    time.keyFrames << KeyFrame.new(1000.ms, handler)
    time.play
  end
end

Hello.launch

実行するとこんな感じ。