Learn JavaFX 8.pdf

(14767 KB) Pobierz
www.allitebooks.com
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
www.allitebooks.com
Contents at a Glance
About the Author ....................................................................................................xxi
About the Technical Reviewers ............................................................................xxiii
Acknowledgments .................................................................................................xxv
Introduction .........................................................................................................xxvii
Chapter 1: Getting Started .....................................................................................
1
Chapter 2: Properties and Bindings.....................................................................
25
Chapter 3: Observable Collections.......................................................................
83
Chapter 4: Managing Stages .............................................................................
127
Chapter 5: Making Scenes .................................................................................
149
Chapter 6: Understanding Nodes .......................................................................
163
Chapter 7: Playing with Colors ..........................................................................
201
Chapter 8: Styling Nodes ...................................................................................
223
Chapter 9: Event Handling .................................................................................
259
Chapter 10: Understanding Layout Panes..........................................................
303
Chapter 11: Model-View-Controller Pattern ......................................................
419
Chapter 12: Understanding Controls .................................................................
435
Chapter 13: Understanding TableView...............................................................
617
Chapter 14: Understanding TreeView ................................................................
663
Chapter 15: Understanding TreeTableView ........................................................
689
Chapter 16: Browsing Web Pages......................................................................
711
v
www.allitebooks.com
CONTENTS AT A GLANCE
Chapter 17: Understanding 2D Shapes ..............................................................
741
Chapter 18: Understanding Text Nodes .............................................................
789
Chapter 19: Understanding 3D Shapes ..............................................................
805
Chapter 20: Applying Effects .............................................................................
841
Chapter 21: Understanding Transformations .....................................................
899
Chapter 22: Understanding Animation ..............................................................
917
Chapter 23: Understanding Charts ....................................................................
953
Chapter 24: Understanding the Image API ........................................................
997
Chapter 25: Drawing on a Canvas ...................................................................
1033
Chapter 26: Understanding Drag and Drop ......................................................
1043
Chapter 27: Understanding Concurrency in JavaFX ........................................
1071
Chapter 28: Playing Audios and Videos ...........................................................
1101
Chapter 29: Understanding FXML ....................................................................
1120
Chapter 30: Understanding the Print API ........................................................
1157
Index ...................................................................................................................
1173
vi
www.allitebooks.com
Introduction
Java had the support for developing GUI applications since its version 1.0 using the AWT (Abstract Windows
Toolkit). Later AWT was replaced by Swing, which gave a little better user experience, but still lacked the
modern-looking widgets and the support for developer’s productivity. Both AWT and Swing lacked the
irst-class support for data binding, eicient GUI rendering engines, easy-to-use 2D and 3D libraries for
developers, and style sheet support. JavaFX was irst released in 2008 as the tool to use for developing rich
Internet applications (RIAs); it used a statically typed declarative language called
JavaFX Script,
which did
not attract a lot of attention from Java developers. JavaFX 2.0, released in 2011, caught the Java community’s
attention when it dropped the support for JavaFX Script and supported writing JavaFX programs using the
Java programming language. In its current version, JavaFX 8 is supported in the Java platform by including
the JavaFX runtime along with the Java runtime in the JRE. Now JavaFX 8 is considered a real successor for
Swing for building the GUI application using the Java platform.
Learn JavaFX
8 shows you how to start developing rich-client desktop applications in JavaFX 8 using
your Java skills. It provides comprehensive coverage of the JavaFX 8 features. Each chapter starts with an
introduction to the topic at hand. A step-by-step discussion of the topic with small snippets of code follows.
At the end of the topic’s discussion, a complete program is presented. Special care has been taken to present
the topics in such a way that chapters can be read serially. he book contains numerous pictures to aid you
in visualizing the GUI that is built at every step in the discussion.
he book starts with an introduction to JavaFX and its history. It lists the system requirements and
the steps to start developing JavaFX applications. It shows you how to create a Hello World application in
JavaFX, explaining every line of code in the process. Later in the book, advanced topics such as 2D and 3D
graphics, charts, FXML, advanced controls, and printing are discussed. Some of the advanced controls such
as TableView, TreeTableView, and WebView are covered in chapters of their own.
I faced few hurdles while writing this book. As JavaFX 8 was being developed, JavaFX 2, the version before
JavaFX 8, was the irst release of JavaFX that used the Java programming language to write JavaFX code. here
were few bugs in JavaFX 2. Sometimes it took me a couple of days of hard work to create an example to work
with, only to realize that there was a bug in it. Later, if something did not work, I would look at the JIRA bug
reports for JavaFX before spending too much time researching it myself. I had to ix bugs as I found them. It
took me 18 months to inish this book and, in the end, it was satisfying to see that what I had produced was a
lot of useful material covering almost every topic in JavaFX so fully that readers could use to learn and build a
rich client application quickly using JavaFX. I hope you will enjoy the book and beneit greatly from it.
I believe that programming is simple if you learn it that way. Keeping this in mind, I kept the examples
in the book as simple as possible, presenting them in as few lines as I could. he examples focus on the topic
being discussed. I do not present complex GUI in my examples, keeping in mind that this could obscure the
learning process of the topic at hand. I have seen books that contain examples that run four or ive pages
long, sometimes even longer; readers of such books (myself included) often get lost in trying to understand
the logic of the program, thus forgetting what they were trying to learn in that section. herefore, simple
programs in this book are intended to help you learn JavaFX faster. he book includes 330 ready-to-run
programs and 430 pictures. Having more pictures than programs is evident from my approach in keeping the
readers’ interest the irst priority. Almost every time I discuss a snippet of code producing a UI, I include the
picture of the results of the UI, so readers are not left to their imaginations as to what the code snippet will
produce. Having to run every snippet of code to see the output can hinder the learning rhythm.
xxvii
www.allitebooks.com
Zgłoś jeśli naruszono regulamin