Chapter 3. JavaFX Script code and structure
This chapter covers
- Writing, inheriting, and using classes
- Mixing code with conditions and loops
- Running code when a variable changes
- Dealing with accidents and the unexpected
In chapter 2 we looked at JavaFX Script’s data types and manipulations; this chapter looks at its code constructs. Separating the two is somewhat arbitrary—we saw plenty of code hiding in the previous chapter’s examples because code and data are flip sides of the same coin. Ahead we’ll see how the concepts we discovered last chapter integrate into the syntax as a whole. Our grounding in data will hopefully engender a more immediate understanding as we encounter conditions, loops, functions, classes, and the like.
As mentioned in chapters 1 and 2, JavaFX Script is what’s referred to as an expression language, meaning most executable bits of code return either zero or one or more values (aka: void, a value, or a sequence). Even loops and conditions will work on the right-hand side of an assignment. It’s important to fix this idea in your mind as we progress through this chapter, particularly if you’re not used to languages working this way. I’ll point out the ramifications as the chapter unfolds.