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.

3.1. Imposing order and control with packages (package, import)

3.2. Developing classes

3.3. Flow control, using conditions

3.4. Sequence-based loops

3.5. Repeating code with while loops (while, break, continue)

3.6. Acting on variable and sequence changes, using triggers

3.7. Trapping problems using exceptions (try, catch, any, finally)

3.8. Summary

sitemap