Java Reference
In-Depth Information
In case you wonder when you should use FXML and when you should program the UI in Java, there is no single
correct answer. In general, declaring a layout is often easier done in FXML, when you use an appropriate tool
(e.g., SceneBuilder). The business logic and wiring is often done in corresponding controller classes. However, the most
important factor is that the developers and designers should find a way that allows them to be the most productive!
Additional Game Enhancements
The Reversi application that was developed in this chapter is completely dynamic and flexible both in layout and
structure, so it is time to take advantage of this and push the limits of your coding skills.
Here are some coding challenges that you can use to take the Reversi application from a well-designed tutorial to
a full-fledged application.
There is one rule that we neglected to implement, which is skipping turns. If, and only if, a
player has no available options to play, the next player can go. Try implementing a facility that
automatically detects whether there are no legal moves and skips a turn.
Playing against another player on the same computer is not nearly as interesting as playing
against a remote opponent. After reading some of the later chapters on back-end integration
with JavaFX, try implementing a network-capable version of the Reversi application.
Wouldn't it be great to have a JavaFX AI for playing Reversi? Give it a try, and see if you can
create an unbeatable opponent!
Summary
In this chapter you were able to fully leverage the JavaFX layout capabilities to do dynamic layout of a complex
application. Along the way, you learned how to
Align
Nodes using bind.
Use
StackPane to layer Nodes and create composite layouts.
Use
TilePane to do fixed-size layouts.
Use
FlowPane , HBox , and VBox to do directional layouts with and without wrapping.
Create a dynamic game board using binding and
GridPane .
Use
AnchorPane to align and stretch overlapping nodes.
Create custom components using
Regions and CSS.
Build a rich UI backed by a game model.
Apply JavaFX effects and transitions.
Use FXML to create the UI in a declarative way.
After experiencing the advantages of dynamic layout, you will be hard-pressed to go back to static positioning of
components with fixed sizes. In the next chapter we show you how to create custom UI components and charts that
you can use to create even more impressive business-centric applications.
 
Search WWH ::




Custom Search