Дата публикации: 04.11.2013 13:49:52
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.
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.
Unfortunately, the application can not be run on the mobile emulator, because the mobile profile of JavaFX API does not support graphical effects yet. If you comment out the code lines that use effects and run the application on the mobile emulator, string formatting will not work properly.
PS. This article was originally posted on the Java.net site.