Table Of ContentBeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 / Front matter
Blind Folio: i
®
Quick Start Guide to
JavaFX™
00-FM.indd 1 2/12/14 5:02 PM
BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5
About the Author
J.F. DiMarzio is a seasoned developer. He began developing
in BASIC on the TRS-80 Color Computer II in 1984. Since
then, DiMarzio has worked in the technology departments of
companies such as the U.S. Department of Defense and the
Walt Disney Company. He continues to strive to push the
limits of technology and develop on new, emerging platforms.
DiMarzio is also an accomplished author. Over the last
12 years, he has released 11 books, including the first edition of
JavaFX: A Beginner’s Guide. His books have been translated
into four different languages and published worldwide.
DiMarzio’s writing style is very easy to read and understand,
which makes the information in the topics he presents more
retainable.
About the Technical Editor
Simon Ritter is the manager of the Java Technology Evangelist
team at Oracle Corporation. Simon has been in the IT business
since 1984 and holds a Bachelor of Science degree in Physics
from Brunel University in the U.K.
Originally working in the area of UNIX development for
AT&T UNIX System Labs and then Novell, Simon moved
to Sun in 1996. At this time he started working with Java
technology and has spent time working both in Java development
and consultancy. Having moved to Oracle as part of the Sun
acquisition, he now focuses on the core Java platform, Java
for client applications, and embedded Java. He also continues
to develop demonstrations that push the boundaries of Java
for applications, such as gestural interfaces, embedded robot
controllers, and in-car systems. Follow Simon on Twitter,
@speakjava, and visit his blog at blogs.oracle.com/speakjava.
00-FM.indd 2 2/10/14 2:32 PM
BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 / Front matter
Blind Folio: iii
®
Quick Start Guide to
JavaFX™
J. F. DiMarzio
New York Chicago San Francisco
Athens London Madrid Mexico City
Milan New Delhi Singapore Sydney Toronto
00-FM.indd 3 2/12/14 5:04 PM
Copyright © 2014 by McGraw-Hill Education (Publisher). All rights reserved. Printed in the United States of America.
Except as permitted under the Copyright Act of 1976, no part of this publication may be reproduced or distributed in any
form or by any means, or stored in a database or retrieval system, without the prior written permission of publisher, with
the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be
reproduced for publication.
ISBN: 978-0-07-180897-2
MHID: 0-07-180897-3
e-book conversion by Cenveo® Publisher Services
Version 1.0
The material in this e-book also appears in the print version of this title: ISBN: 978-0-07-180896-5,
MHID: 0-07-180896-5
McGraw-Hill Education e-books are available at special quantity discounts to use as premiums and sales
promotions, or for use in corporate training programs. To contact a representative, please visit the Contact Us
pages at www.mhprofessional.com.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. All other trademarks are the property of their
respective owners, and McGraw-Hill Education makes no claim of ownership by the mention of products that contain
these marks.
Screen displays of copyrighted Oracle software programs have been reproduced herein with the permission of Oracle
Corporation and/or its affiliates.
Information has been obtained by McGraw-Hill Education from sources believed to be reliable. However, because of the
possibility of human or mechanical error by our sources, McGraw-Hill Education, or others, McGraw-Hill Education
does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or
omissions or the results obtained from the use of such information.
Oracle Corporation does not make any representations or warranties as to the accuracy, adequacy, or completeness of any
information contained in this Work, and is not responsible for any errors or omissions.
TERMS OF USE
This is a copyrighted work and McGraw-Hill Education (“McGraw-Hill”) and its licensors reserve all rights in and to the
work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to
store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create
derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without
McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use; any other use of the
work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms.
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR
WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED
FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE
WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained
in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor
its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or
for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed
through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental,
special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of
them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause
whatsoever whether such claim or cause arises in contract, tort or otherwise.
eBook 309-3cr_pg.indd 1 2/14/14 6:25 PM
BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 / Front matter BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 / Front matter
Blind Folio: iv Blind Folio: v
Neil, a great ally and agent over the last ten years.
00-FM.indd 5 2/10/14 2:32 PM
This page has been intentionally left blank
BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 / Front matter BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 / Front matter
Blind Folio: vi
Contents at a Glance
1 Introduction to JavaFX ................................................... 1
2 Setting the Scene .......................................................... 9
3 Hello World ................................................................ 25
4 Using JavaFX Layouts .................................................... 41
5 Creating Shapes ........................................................... 53
6 Using Colors and Gradients ............................................... 77
7 Using Images .............................................................. 89
8 Applying Effects and Transformations .................................... 101
9 Basic Animation ........................................................... 129
10 Using Events ............................................................... 141
11 Custom Nodes and Subclassing ........................................... 157
12 Working with WebView ................................................... 169
13 Style Your JavaFX with CSS .............................................. 181
14 Embedded Media .......................................................... 193
vii
00-FM.indd 7 2/10/14 2:32 PM
BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5
viii Quick Start Guide to JavaFX
A Packaging and Deploying JavaFX ......................................... 213
B The Swing of Things ....................................................... 221
C Answers to Self Tests ...................................................... 225
Index ...................................................................... 237
ix
00-FM.indd 8 2/10/14 2:32 PM
BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 BeginNew / Quick Start Guide to JavaFX™ / Jerry DiMarzio / 896-5 / Front matter
Contents
INTRODUCTION .................................................................. xiii
1 Introduction to JavaFX ................................................... 1
What Is JavaFX? .................................................................... 2
What Is Needed for JavaFX Development? .......................................... 2
Required Skills and Knowledge ............................................... 3
Required Software ............................................................ 3
Required Hardware ........................................................... 4
Downloading and Installing
the Required Software ........................................................... 5
NetBeans ..................................................................... 5
Try This: Configure Your NetBeans ................................................. 8
Chapter 1 Self Test ................................................................. 8
2 Setting the Scene .......................................................... 9
Creating a New JavaFX Project ..................................................... 10
The (Not-so) Empty JavaFX Project ........................................... 12
Examining the Project Files ................................................... 14
Exploring the Project in NetBeans ............................................ 14
Working with the JavaFXForBeginners.java File .................................... 17
The Comments ............................................................... 17
The package Statement ....................................................... 19
Your First Stage .................................................................... 20
The Application Entry Point .................................................. 20
The Sample.fxml File ............................................................... 21
Compiling Your JavaFX Application ................................................ 23
Chapter 2 Self Test ................................................................. 23
ix
00-FM.indd 9 2/10/14 2:32 PM