Introducing ClockControl

Before adding a new style class, let's start by converting out Clock application into a ClockControl which can be used in any application like other JavaFX nodes.

It will not be a full-fledged Control, but a first step. We'll talk about making a real Controls in Chapter 10, Advanced Controls and Charts.

I've made the following changes in order to prepare for CSS handling:

  • Made the ClockControl class extend BorderPane
  • Moved all graphics initialization to the ClockControl constructor
  • Simplified timing logic; the old one was needed to demonstrate the JavaFX API from Chapter 1, Stages, Scenes, and Layout, and Chapter 2, Building Blocks – Shapes, Text, and Controls.

The following is the resulting source code:

// chapter6/cssapi/ClockControl.java ...

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.