Chapter 4. Swing by numbers
This chapter covers
- Practicing core JavaFX Script skills
- Using model/view/controller, without reams of boilerplate
- Building a user interface that swings
- Validating a simple form
You’ve had to take in a lot in the last couple of chapters—an entirely new language, no less! I know many of you will be eager to dive straight into creating media-rich applications, but you need to learn to walk before you can run. JavaFX Script gives us a lot of powerful tools for writing great software, but all you’ve seen thus far is a few abstract examples.
So for this, our first project, we won’t be developing any flashy visuals or clever animations. Be patient. Instead we need to start putting all the stuff you learned over the last few dozen pages to good use. A common paradigm in UI software is Model/View/Controller, where data and UI are separate, interacting by posting updates to each other. The model is the data, while the view/controller is the display and its input. We’re going to develop a data class and a corresponding UI to see how the language features of JavaFX Script allow us to bind them together (pun only partially intended). But first we need to decide on a simple project to practice on, something fun yet informative.
We’re going to develop a version of the simple, yet addictive, number puzzle game found in countless newspapers and magazines around the world. If you’ve never encountered such puzzles before, take a look at figure 4.1.