Book Author, Blogger, a wannabe GUI guy, JavaFX enthusiast, Groovy, mobile phones, AI and most importantly husband and proud father of two awesome kids. Carl is a DZone MVB and is not an employee of DZone and has posted 15 posts at DZone. You can read more from them at their website. View Full User Profile

JavaFX in Action

11.11.2009
| 14750 views |
  • submit to reddit
Published by: Manning
ISBN: 1933988991

Reviewer Ratings

Relevance:
4

Readability:
5

Overall:
5

Buy it now

One Minute Bottom Line

Well organized, JavaFX in Action enables beginners, as well as experienced developers from any language background, to immediately hit the ground running with the JavaFX platform.  This book provides great examples that demonstrate the abilities of JavaFX to create engaging Rich Internet Applications (RIA) ranging from game programming to business applications. While the book has a strong focus on the fundamentals of the JavaFX Script language (two chapters and Appendix B to be exact), it also details the new JavaFX 1.2.x controls API (Chapter 7). The author, having a good sense of humor, keeps the reader alert and capable of digesting technical jargon. By including many bonus sections the author keeps you wanting more information. JavaFX in Action is definitely a teaching style book with concise code blocks containing great comments along with outputs (displayed results) after a program is run, thus freeing the reader from having to be handcuffed to their compilers. There are lots of FAQs which challenges your ability to think in real world situations when using the JavaFX language and APIs.

Review

It is an exciting time to learn JavaFX platform to build desktop, mobile and Set-Top Box applications. JavaFX in Action is a book that will get you up to speed in no time at all. The book strikes a good balance between fun (games) and serious (business) examples to teach you many application development concepts. So, without further adieu.

Chapter 1, Welcome to the Future: introducing JavaFX, begins by discussing the history of rich applications and graphics programming for desktop applications. It goes on to explain and answer questions such as "What is a DSL?" and "why do we need yet another language?" Furthermore, it emphasizes how JavaFX the language syntax is expression based, providing tight integration with object models and the code which controls them. It then provides a comparison of competing technologies such as Adobe AIR, GWT and Silverlight. Lastly, the end of this chapter suggests that the reader follow Appendix A for instructions on how to download and install the latest JavaFX SDK along with the NetBeans, Eclipse and IntelliJ IDE for folks to get started.

Chapter 2, JavaFX Script: data and variables, delves into the fundamentals of the JavaFX Script language when dealing with various data types and how to declare variables.  An interesting note is that unlike Java primitives all JavaFX Script value types are objects. It then shows all the JavaFX Script data types along with its equivalent Java data types in a comparison chart. As a surprise this chapter was larger than at first glance. Chapter 2 is packed with numerous concepts which are as follows: commenting, outputting, literals, strings manipulation, arithmetic operators, logical operators, casting, character escaping, data formatting, time literals, predicates, embedded expressions, checking types, internationalization, sequences, avoiding naming conflicts, functions, binding variables, binding functions and minimal recalculation. Lastly, it then goes on to discuss native arrays on how to use them, but warns that "It may be modified, or even removed, in later revisions of the JavaFX Script language".

Chapter 3, JavaFX Script: code and structure, continues with the fundamentals of the JavaFX Script language by demonstrating code organization and object oriented programming concepts.  Introduced to the JavaFX Script language is the Mixin class, which is a type of multiple inheritance that solves certain edge cases and providing interoperability with Java's inheritance model. It later provides an excellent Question and Answer (Q&A) section covering most situations using inheritance with interfaces, abstract classes, mixins, abstract functions and concrete classes. A similar mechanism like binding, this chapter explains about triggers. Triggers are quite analogous to the proxy pattern or Java Swing's property change support facility, but used in context when modifying variables and sequences. Lastly, exception handling is discussed on how to use the try, catch, any and finally keywords.

Chapter 4, Swing by numbers, begins by establishing the fundamentals of the JavaFX Script language, with the very first project that shows you how to create the popular and addictive game called Sudoku. While using many of the JavaFX language features from prior chapters this chapter also covers how to use existing Swing Components in JavaFX applications. The intent here was to allow developers to have a migration path from existing Swing controls as new JavaFX controls are being created. This chapter like later chapters will frequently emphasize on the topic of layout and positioning nodes on the Scene Graph. The chapter ends with a bonus section that teaches you how to create a form containing user validation with JavaFX's wrapped Swing controls. As the user enters invalid values, visual feedback indicators (warnings icons beside text box control) appear on the form quite magically.

Chapter 5, Behind the scene graph, explores the heart of JavaFX (The Scene Graph API.) It begins by discussing the difference between retained mode vs. immediate mode when displaying graphics widgets onto the screen. Being that JavaFX's scene graph is a retained mode system it maintains a structure of elements to be displayed. It further explains the basic elements that are displayed onto the scene graph which are Nodes and Groups. While a node is a single element such as a line or rectangle, a group is a node grouping many nodes. Next, is one the coolest parts of the book where we get into the topic of animation.  In very good detail it shows us the Timeline and KeyFrame objects, that enable developers to interpolate variables to assist in scaling, transforming and even translating nodes and their positions on the scene graph (display area,) thus making nodes move across the screen effortlessly. Lastly, it discusses about the positioning of nodes correctly when translating nodes onto the scene graph by using layout vs. translation of coordinates.  In addition there is a bonus section on creating a commonly used control, the hyperlink style label control.

Chapter 6, Moving Pictures, brings most of the prior concepts together to form a excellent UI interface to create a usable Media Player Application that plays media files. It covers how to make custom nodes for controls and their behaviors during different states such as building animated buttons. It then reinforces the reader regarding the differences between prior versions of 1.2 create() and init() functions within the CustomNode class. Next, it goes into more detail about layout management for positioning nodes when resizing of nodes relative to one another. A really nice list and List Pane control similar to the iPhone's kinetic scrolling is fully explained in this section that is used in the media player. This chapter also teaches about many graphical effects such as gradients and reflections on nodes to further enhance the media player’s interface. After, discussing all things UI it explains to the reader on how to wire up the front end UI with JavaFX's media API. Once wired up it enables the developer to playback media such as audio or video file formats. Lastly, it ends by adding another bonus to our UI arsenal, Custom fonts! Here it demonstrates using and bundling custom fonts in your rich applications, thus guaranteeing the same font across all systems.

Chapter 7, Controls, charts and storage, begins by covering the following JavaFX 1.2 controls: buttons, text fields, radio buttons, and sliders. The example project creates a form type application that helps collect user feedback information. Similar to chapter 4's bonus section relating to input validation on a form and dynamically generating warning indicators while a user is typing invalid data. The contrast between chapter 4's bonus section is that in this example it is using 100% JavaFX controls instead of using Swing wrapper controls, thus making controls portable across the various profiles(desktop, mobile, tv.) Next, is the cross platform persistent storage API enabling JavaFX to retrieve and store data locally. Bringing many things together an example application demonstrates using the storage API to load data and subsequently visually graphing the data using JavaFX chart controls APIs such as: 3D pie, bar, area, bubble, line, 2D pie and scatter. Lastly, is a bonus section on skinning controls using cascading style sheets (CSS) or the JavaFX's Skin API. Skinning allows a developer to swap stylized skins (themes) on controls making professional looking applications with ease. The example demonstrates using a different skins being swapped out on a progress bar type control.

Chapter 8, Web services with style, introduces JavaFX's ability to build rich client applications while capable of communicating with popular Web services such as Flickr. The book demos another usable application called the Flickr Image Viewer . Not only is the application attractive and fun, but it demonstrates how to properly make asynchronous callbacks through http requests that subsequently process results to be displayed without blocking the main GUI thread. It continues to explain how to parse two popular Web service data formats: XML and JSON. Also, the chapter explores the most commonly used transition effects such as: Fade, Rotate, Translate and Scale. These transition effects enable a developer to animate between a node's visual state with extreme ease. Lastly, the chapter provides a very good explanation regarding how a node's bounds are used in different contexts while using the layoutBounds, boundsInLocal and boundsInParent attributes. The book suggests that the layoutBounds is used more often to lay out nodes and that it precludes (drop shadow, clip, etc.) the calculations that alter the size of the node.

Chapter 9, From app to applet, provides an interesting demo project that replicates the famous Enigma cipher machine used in the German military during the 1920s. Here, it begins by discussing the designer/developer workflow roles. To demonstrate both roles it was a nice treat to use the open source product called Inkscape to create graphical assets (Adobe Photoshop and Illustrator are also discussed.) Inkscape is similar to Adobe Illustrator enabling a designer to create a scalable vector graphic SVG file and subsequently converted by using the JavaFX Production Suite to then be used and manipulated by JavaFX programs. It further covers the details on how to access and manipulate the content to be used as nodes on the scene graph.

Chapter 10, Clever graphics & smart phones, covers the mobile profile using the JavaFX platform. This chapter begins with a project that involves in creating a three dimensional looking game made for smart phones. This chapter shows you how to use an excellent technique that makes things appear 3D without having to perform real 3D calculations, thus making it less CPU intense on small devices such as mobile phones. It goes on to explain how to provide event handling whenever the mobile user presses buttons to navigate in the game. It then covers how to package mobile applications to be deployed and eventually run. After, finished packaging the mobile application it teaches you how to run the application on a mobile emulator through the Netbeans IDE. Once the application has run on an emulator the next section covers how to run and deploy the application on a real mobile device. Lastly, the author offers many optimization strategies to maximize performance. One simple tip that most folks should know by now, is what the book warns: "Avoid binding to data that is unlikely to change during the lifetime of the application."

Chapter 11, The best of both worlds: using JavaFX from Java, explores the possibilities of using JavaFX code from within Java code. You will learn how to use JavaFX code as a dynamic scripting language and how to use JavaFX code already compiled from Java code. Another fun example project the book presents is how to dynamically script events for an isometric view type adventure game. During game play from within Java code, you will be capable of dynamically executing JavaFX script blocks when the player triggers various game events. Lastly, it covers elegant strategies for interoperability between the two languages using Java interfaces.

Appendix A, Getting started, covers where and how to obtain the JavaFX software and the installation instructions. It also discusses optional IDEs and the JavaFX Production Suite. Once the software is installed this section teaches you how to set path information, running the compiler and running the compiled application. Lastly, it provides a list of most common links to JavaFX information and blogs to assist the developer.

Appendix B, JavaFX script: A very quick reference, enables developers to quickly look up simple JavaFX Script language APIs and examples.

Appendix C, Not familiar with Java?, provides background information to reinforce a developer who might not be familiar with Java and how it is associated with JavaFX. It begins by explaining the difference between static and dynamically typed languages. Readers new to Java may find this section familiar with other object oriented languages. It also discusses JavaFX and how it relates to the Java language. This chapter continues to cover JavaFX with the following topics: casting, packages, inheritance and access modifiers.

Appendix D, JavaFX and the Java platform, is a very good overview that details how JavaFX and Java can coexist as a platform. It further explains the three Java editions where JavaFX is possible. Lastly, it points out the two types of audiences when it comes to rich applications the user and the programmer.

In conclusion, JavaFX in Action is easy to read and I highly recommend getting the book. Overall, it is more of a teaching style book rather than a reference style book. Also, I find that all the bonus sections are excellent and quite useful in the real world. I am sure you'll enjoy the book as much as I have. So, I encourage folks to check it out!

Further resources that I recommend are: 

Published at DZone with permission of Carl Dea, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)