Table of 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 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 JavaFX For Beginners.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
3 Hello World 25
What Is MVC? 26
Using JavaFX Scene Builder 27
Working with Containers 28
Working with Controls 30
Creating Your Own Hello World Application 32
Using JavaFX Binding 33
An Introduction to Methods and Properties 35
Java Methods 35
JavaFX Properties 37
Chapter 3 Self Test 40
4 Using JavaFX Layouts 41
The HBox 43
The VBox 47
Nested Layouts 48
Try This: Using Other Layouts 51
Chapter 4 Self Test 52
5 Creating Shapes 53
JavaFX Scene Graph 54
Drawing Shapes 55
Before You Begin 55
Lines 56
Rectangles 65
Polygons 68
Arcs 69
Circcles and Ellipses 72
Try This: Create Multiple Shapes 75
Chapter 5 Self Test 75
6 Using Colors and Gradients 77
Using Color 78
Predefined Colors 78
Mixing Colors 80
Using Gradients 83
Linear Gradients 83
Radial Gradients 86
Try This: Create a Custom Gradient 87
Chapter 6 Self Test 88
7 Using Images 89
The Image View Node 90
The Image Class 91
Try This: Working with Different Image Types 97
The Canvas 97
Chapter 7 Self Test 99
8 Applying Effects and Transformations 101
Effects 104
Bloom 105
Color Adjust 107
Gaussian Blur 108
Glow 111
DropShadow 113
Lighting 116
SepiaTone 120
Transformations 122
XY Transformations 123
Rotation 123
Perspective Transform 124
Try This: Combining Multiple Effects 127
Chapter 8 Self Test 127
9 Basic Animation 129
Timelines 131
Animating Along a Path 136
Try This: Create a Path Animation 140
Chapter 9 Self Test 140
10 Using Events 141
What Are Events? 142
Mouse Events 142
Key Events 151
Chapter 10 Self Test 155
11 Custom Nodes and Subclassing 157
Subclassing Node 158
Creating a Round Button 159
Try This: Create Your Own Shapes 166
Chapter 11 Self Test 166
12 Working with WebView 169
Rendering HTML 171
Communicating Between JavaScript and JavaFX 172
Chapter 12 Self Test 179
13 Style Your JavaFX with CSS 181
Adding a Style Sheet to Your Packages 183
Creating a Style 186
Using Your Styles 187
Creating Independent Style Classes 190
Try This: Experimenting with Styles 192
Chapter 13 Self Test 192
14 Embedded Media 193
Playing Video 195
Creating a Play/Pause Button 199
Chapter 14 Self Test 211
Playing Video 195
Creating a Play/Pause Button 199
Creating a Progress Indicator 205
Chapter 14 Self Test 211
A Packaging and Deploying JavaFX 213
JavaFX Packager Tool 214
Self-Contained Application Packages 218
Web Start 219
B The Swing of Things 221
JavaFX Swing Compatibility 22
Putting JavaFX in Swing Apps 223
C Answers to Self Tests 225
Chapter 1 226
Chapter 2 226
Chapter 3 227
Chapter 4 228
Chapter 5 229
Chapter 6 229
Chapter 7 230
Chapter 8 231
Chapter 9 232
Chapter 10 232
Chapter 11 233
Chapter 12 234
Chapter 13 235
Chapter 14 235
Index 237