100% found this document useful (1 vote)
597 views

JavaFX 1 2 Application Development Cookbook 1st Edition Vladimir Vivien - Read the ebook online or download it to own the complete version

The document provides information about the 'JavaFX 1.2 Application Development Cookbook' by Vladimir Vivien, which includes over 80 recipes for creating rich Internet applications. It details the book's content, including chapters on getting started, creating applications, animations, media, and deployment practices. Additionally, it offers links to download the book and other related ebooks from ebookultra.com.

Uploaded by

vaetaticuru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
597 views

JavaFX 1 2 Application Development Cookbook 1st Edition Vladimir Vivien - Read the ebook online or download it to own the complete version

The document provides information about the 'JavaFX 1.2 Application Development Cookbook' by Vladimir Vivien, which includes over 80 recipes for creating rich Internet applications. It details the book's content, including chapters on getting started, creating applications, animations, media, and deployment practices. Additionally, it offers links to download the book and other related ebooks from ebookultra.com.

Uploaded by

vaetaticuru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Visit https://ebookultra.

com to download the full version and


explore more ebooks or textbooks

JavaFX 1 2 Application Development Cookbook 1st


Edition Vladimir Vivien

_____ Click the link below to download _____


https://ebookultra.com/download/javafx-1-2-application-
development-cookbook-1st-edition-vladimir-vivien/

Explore and download more ebooks or textbooks at ebookultra.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

wxPython 2 8 Application Development Cookbook First


Edition Cody Precord

https://ebookultra.com/download/wxpython-2-8-application-development-
cookbook-first-edition-cody-precord/

Professional Android 2 Application Development 1st Edition


Reto Meier

https://ebookultra.com/download/professional-android-2-application-
development-1st-edition-reto-meier/

Java 2 micro edition application development Michael Kroll

https://ebookultra.com/download/java-2-micro-edition-application-
development-michael-kroll/

SproutCore Web Application Development 1st Edition Keating

https://ebookultra.com/download/sproutcore-web-application-
development-1st-edition-keating/
Mastering MeteorJS Application Development 1st Edition V

https://ebookultra.com/download/mastering-meteorjs-application-
development-1st-edition-v/

Architecture and ideology 1. publ. Edition Vladimir Mako

https://ebookultra.com/download/architecture-and-ideology-1-publ-
edition-vladimir-mako/

OpenCV Computer Vision Application Programming Cookbook


2nd Edition Robert Laganiere

https://ebookultra.com/download/opencv-computer-vision-application-
programming-cookbook-2nd-edition-robert-laganiere/

iOS Game Development Cookbook 1st Edition Jonathon Manning

https://ebookultra.com/download/ios-game-development-cookbook-1st-
edition-jonathon-manning/

HTML5 Mobile Development Cookbook 1st Edition Shi Chuan

https://ebookultra.com/download/html5-mobile-development-cookbook-1st-
edition-shi-chuan/
JavaFX 1 2 Application Development Cookbook 1st
Edition Vladimir Vivien Digital Instant Download
Author(s): Vladimir Vivien
ISBN(s): 9781847198945, 1847198945
Edition: 1
File Details: PDF, 3.54 MB
Year: 2010
Language: english
­

JavaFX 1.2 Application


Development Cookbook

Over 80 recipes to create rich Internet applications with


many exciting features

Vladimir Vivien

BIRMINGHAM - MUMBAI
JavaFX 1.2 Application Development Cookbook

Copyright © 2010 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is sold
without warranty, either express or implied. Neither the author, nor Packt Publishing
and its dealers and distributors will be held liable for any damages caused or alleged
to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: August 2010

Production Reference: 1170810

Published by Packt Publishing Ltd.


32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.

ISBN 978-1-847198-94-5

www.packtpub.com

Cover Image by Karl Moore ([email protected])


Credits

Author Editorial Team Leader


Vladimir Vivien Akshara Aware

Reviewers Project Team Leader


Anghel Leonard Priya Mukherji

Luca Masini
Project Coordinator
Meenakshi Verma
Leena Purkait

Acquisition Editor
Proofreader
Sarah Cullington
Clyde Jenkins

Development Editor
Production Coordinator
Dhwani Devater
Melwyn D'sa
Reshma Sundaresan

Cover Work
Technical Editors
Melwyn D'sa
Aaron Rosario
Mohd. Sahil

Indexer
Hemangini Bari
Tejal Daruwale
About the Author

Vladimir Vivien is a software engineer living in the United States. Past and current
experience include development in Java and .Net for industries including publishing,
financial, and healthcare. He has worked with a varied number of technologies including
user-facing GUI frontends and backend middleware. Vladimir enjoys taking part in open
source projects. He is the author of JmxBuilder a Groovy DSL for instrumentation and
management that is now part of the core Groovy project. Vladimir has presented some
of his ideas at JavaOne, NFJS Software Symposium, and local Java user groups.

Besides JavaFX, he has a wide range of technology interests including Java, OSGi, Scala,
BugLabs, Arduino, SunSPOT, and any other interesting projects running on the JVM. You
can follow Vladimir through his blog: http://blog.vladimirvivien.com/, Twitter:
http://twitter.com/vladimirvivien, and LinkedIn: http://www.linkedin.com/
in/vvivien.

Firstly, I want to thank my wife for her support, especially during the crunch
period when I would lock myself in my office for hours to finish a chapter.
I also want to thank everyone who offered kind and encouraging words
that kept me going when I wanted to literally walk away from the project.

A special shout out goes to Sarah Cullington, my editor, who is the reason
that this book exists. Thank you, Sarah, for not giving up on the project
despite its many setbacks. Thanks to the entire Packt Publishing team
for taking the risk in a new author like myself, and in a nascent technology
like JavaFX.

Finally, I must give a shout out to to the Sun team, who saw the need for a
declarative language for rich client development on the VM, and seized the
opportunity to bring JavaFX to life. Although JavaFX is new in this space,
thanks to the hard work of these dedicated engineers, JavaFX is a complete
platform with a complete toolset for developing rich and engaging visual
applications on the JVM.
About the Reviewers

Anghel Leonard is a senior Java developer with more than 12 years of experience
in Java SE, Java EE, and the related frameworks. He wrote and published more than
20 articles about Java technologies, and more than 100 tips and tricks. He also wrote
two books about XML and Java (one for beginners and one for advanced readers), and
one about JBoss Tools 3.0, with Packt Publishing. During this time, he developed web
applications using the latest technologies on the market. In the past two years, he has
been focused on developing RIA projects for GIS fields. He is interested in bringing as
much desktop as possible to the Web; therefore, GIS applications represents a real
challenge for him.

Luca Masini is a Senior Software Engineer and Architect, who started as a game
developer for Commodore 64 (Football Manager) and Commodore Amiga (Ken il
guerriero). He soon turned to object-oriented programming, and for that, he was
always attracted by the Java language, right from its beginning in 1995.

After having found his passion, he worked as a consultant for major Italian banks,
developing and integrating the main software projects for which he often took technical
leadership. He was able to adopt Java Enterprise in an environment where COBOL was
the flagship platform, converting it from mainframe-centric to distributed.

He then set his eyes upon open source technologies, starting from Linux and then
with enterprise frameworks, with which he was able to introduce some low-impact
concepts, such as IoC, ORM, MVC, and so on. For the the same reason, he was also
an early adopter of Spring, Hibernate, Struts, and a whole host of other technologies
that, in the long run, have given his customers a technological advantage, and
therefore a development cost-cut.
Lately, however, his attention has been completely directed towards the simplification and
standardization of development with Java EE, and for this reason, he is working at the
ICT of a large Italian company to introduce advanced build tools (Maven and Continuous
Integration), archetypes of project, and Agile Development with plain standards.

He has worked on the following books (from Packt):

ff Google Web Toolkit


ff Spring Web Flow 2
ff Spring Persistence with Hibernate

Gaga tu sei qui. Ah tu non fuggi. Tu mi risponderai fino all'ulitmo grido.

Meenakshi Verma has been a part of the IT industry since 1998. She is experienced
in putting up solutions across multiple industry segments using SAP BI, SAP Business
Objects, and Java/J2EE technologies. She is currently based in Toronto, Canada, and
is working with Enbridge Gas Distribution.

Meenakshi has been helping with technical reviews for books published by Packt
publishing across varied enterprise solutions. Her earlier works include JasperReports
for Java Developers, Java EE 5 Development using GlassFish Application Server, Practical
Data Analysis and Reporting with BIRT', and EJB 3 Developer's Guide, Learning DOJO.

I'd like to thank my father (Mr. Bhopal Singh) and mother (Mrs. Raj Bala) for
laying a strong foundation in me and giving me their unconditional love and
support. I also owe thanks and gratitude to my husband (Atul Verma) for his
encouragement and support throughout the review of this book, and many
others: my four year old son (Prieyaansh Verma) for giving me the warmth
of his love despite my hectic schedules, and my brother (Sachin Singh) for
always being there for me.
This book is dedicated to my son MJV: his smile is my daily inspiration.
Table of Contents
Preface 1
Chapter 1: Getting Started with JavaFX 7
Introduction 7
Installing the JavaFX SDK 9
Setting up JavaFX for the NetBeans IDE 11
Setting up JavaFX for the Eclipse IDE 16
Using javafxc to compile JavaFX code 19
Creating and using JavaFX classes 22
Creating and using variables in JavaFX 25
Using binding and triggers to update variables 28
Creating and using JavaFX functions 32
Integrating your JavaFX code with Java 35
Creating and using JavaFX sequences 37
Working with JavaFX String 41
Chapter 2: Creating JavaFX Applications 45
Introduction 45
Building a JavaFX application 46
Drawing simple shapes 50
Creating complex shapes using Path 55
Creating shapes with constructive area geometry 57
Drawing letter shapes using the Text class 60
Handling user input 64
Arranging your nodes on stage 67
Making your scripts modular 70
Creating your own custom node 73
Controlling your application's window style 76
Going full-screen 79
Table of Contents

Chapter 3: Transformations, Animations, and Effects 81


Introduction 82
Modifying shapes with the Transformation API 82
Creating simple animation with the Transition API 85
Composing animation with the Transition API 89
Building animation with the KeyFrame API 93
Creating custom interpolators for animation 100
Morphing shapes with the DelegateShape class 102
Using data binding to drive animation sequences 104
Applying cool paint effects with gradients 107
Creating your own customized Paint 109
Adding depth with lighting and shadow effects 111
Creating your own Text effect 114
Adding visual appeal with the Reflection effect 116
Chapter 4: Components and Skinning 119
Introduction 119
Creating a form with JavaFX controls 120
Displaying data with the ListView control 125
Using the Slider control to input numeric values 128
Showing progress with the progress controls 131
Creating a custom JavaFX control 134
Embedding Swing components in JavaFX 139
Styling your applications with CSS 143
Using CSS files to apply styles 148
Skinning applications with multiple CSS files 152
Chapter 5: JavaFX Media 157
Introduction 157
Accessing media assets 158
Loading and displaying images with ImageView 159
Applying effects and transformations to images 163
Creating image effects with blending 167
Playing audio with MediaPlayer 172
Playing video with MediaView 175
Creating a media playback component 179
Chapter 6: Working with Data 185
Introduction 185
Saving data locally with the Storage API 186
Accessing remote data with HttpRequest 189
Downloading images with HttpRequest 192
Posting data to remote servers with HttpRequest 196
ii
Table of Contents
Uploading files to servers with HttpRequest 200
Building RESTful clients with the PullParser API 204
Using the Feed API to create RSS/Atom clients 213
Visualizing data with the JavaFX chart API 220
Chapter 7: Deployment and Integration 225
Introduction 225
Building and packaging your app with an IDE 227
Building and packaging your app with javafxpackager 229
Packaging your app to be Web Start(ed) 232
Packaging your app as an applet 237
Passing arguments to JavaFX applications 242
Making your applets drag-to-install 245
Controlling JavaFX applets from JavaScript 250
Chapter 8: The JavaFX Production Suite 259
Introduction 259
Loading multiple images dynamically 260
Exporting Adobe Photoshop graphics to JavaFX 265
Exporting Adobe Illustrator graphics to JavaFX 269
Exporting Scalable Vector Graphics (SVG) to JavaFX 274
Using objects loaded from FXZ files 277
Appendin A: Mobile JavaFX 285
Appendin B: JavaFX Composer 287
Appendin C: JavaFX Products and Frameworks 289
Appendin D: Best Practices for Development 291
Appendin E: Best Practices for Deployment 295
Index 299

iii
Preface
This book is a collection of code recipes, examples, and informative discourses designed
to enable the reader to get started with creating JavaFX application quickly. The book is
arranged as a series of loosely related code recipes that a reader can easily select to fit
his or her needs. It exposes readers to a great variety of topics designed to satisfy different
skill levels. Readers will learn about the language, animation techniques, paints, effects,
JavaFX controls, integration of Swing components, styling with CSS, audio/video, deployment
practices, and JavaFX integration with Adobe design tools.

What this book covers


Chapter 1, Getting Started with JavaFX... This is the "getting started" chapter of the book. It
provides introductory materials to the platform, including installation instructions to get your
environment set up. It also covers language basics such as classes, data types, function
usage, variable declaration, data binding, triggers, Java and JavaFX integration.

Chapter 2, Creating JavaFX Applications... This chapter covers the essential building blocks
of the JavaFX application framework, including primitive shapes, path, text, constructive area
geometry, mouse/keyboard input, custom node, and window styling.

Chapter 3, Transformations, Animations, and Effects... This chapter explores the animation
capabilities supported in JavaFX. You start with the Transition API to quickly build simple
animations. The material continues to cover the KeyFrame API for more advanced animation
sequences. You will learn about colors, effects, and how to create your own custom paint
and effects.

Chapter 4, Components and Skinning... This chapter is divided into two sections. The first
section shows readers how to use the set of standard JavaFX controls. The chapter also
shows how to embed Swing components in your JavaFX scene graph. You will also learn how
to create your own custom visual controls. The second section of the chapter introduces the
reader to JavaFX's support for CSS. The reader will learn how to style controls using inline
and externalized CSS to create skins.
Preface

Chapter 5, JavaFX Media... One of the exciting features of JavaFX is its inherent support for
multimedia. JavaFX includes support for rendering of images in multiple formats and support
for playback of audio and video on all platforms where JavaFX is supported. In this chapter,
readers learn how to display and manipulate images using the Image API. They will also learn
how to playback both audio and video using the Media API. The chapter shows also how to
create practical custom playback controls.

Chapter 6, Working with Data... JavaFX provides superb support for accessing and
manipulating data both locally and remotely. In this chapter, readers are introduced to the
Storage API for local data storage. It provides extensive coverage of JavaFX's HttpRequest API
for accessing data on remote web servers. Readers will learn how to use JavaFX's XML and
JSON parsers to build RESTful client mashups using popular services such as Google Map,
Yahoo Weather, and Zillow Listing. Finally, the chapter explores JavaFX's built-in Chart API for
data visualization.

Chapter 7, Deployment and Integration... This chapter provides coverage of the deployment
mechanism supported by JavaFX. Readers will learn how to properly build and package their
applications to target the different runtimes supported by JavaFX, including the web browser
and the desktop. Readers learn how to create Java Web Start-ready applications using the
build tools included in the SDK. The chapter shows how to write JavaScript that communicates
with your JavaFX applet while running within the browser.

Chapter 8, The JavaFX Production Suite... This chapter covers JavaFX's integral support for
designer tools from Adobe, including Illustrator and Photoshop. Readers are walked through
the process of exporting creative assets using the JavaFX Production Suite plugins available
for these tools. The chapters also shows how to integrate exported objects from Photoshop
and Illustrator into JavaFX.

Appendix A, Mobile JavaFX... In this appendix, readers learn about JavaFX's support for mobile
development. You will learn about development techniques to target mobile devices and tool
support available to get your JavaFX app in the mobile space.

Appendix B, JavaFX Composer... By the time you get your hands on this book, JavaFX
Composer will be available as part of NetBeans. This appendix introduces the reader
to the tool and its features.

Appendix C, JavaFX Products and Frameworks... This appendix introduces the user to the
community support that is developing around JavaFX. Readers learn about several open
source projects and commercial tools available for JavaFX.

Appendix D, Best Practices for Development... As the tile of this appendix indicates, readers
will learn about key practices to use when creating JavaFX development.

Appendix E, Best Practices for Deployment... This appendix is a continuation of chapter 7. It


discusses practices that should be applied when building and deploying JavaFX applications.

2
Preface

What you need for this book


ff JavaFX SDK 1.2
ff Java Development Kit (JDK)
ff NetBeans or Eclipse
ff JDK 6 update 14 (or later)

Who this book is for


This book is for Java developers, RIA content developers, and graphic designers who want to
build RIAs featuring animations, videos and other feature-rich content. If you have knowledge
of Java, JavaScript, JavaFX components, you can exploit this book to your advantage.

Conventions
In this book, you will find a number of styles of text that distinguish between different kinds
of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of
the include directive."

A block of code is set as follows:


<jnlp>
...
<resources>
<j2se version="1.5+" java-vm-args="-Xmx256M"/>
...
</resources>
...
</jnlp>

When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
<jnlp>
...
<application-desc
main-class="com.sun.javafx.runtime.main.Main">
<argument>MainJavaFXScript=param.demo.Main</argument>
<argument>name=World</argument>
</application-desc>
...
</jnlp>

3
Preface

Any command-line input or output is written as follows:


javafxpackager -src src -appClass params.RuntimeArgsApplet
-appName args-demo
-appVendor "Vladimir Vivien" -appVersion 1.0
-appCodebase "http://my.server/path/to/app/"
-appWidth 640 -appHeight 75

New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "clicking on the Next button
moves you to the next screen".

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to develop
titles that you really would like to see.

To send us general feedback, simply send an e-mail to [email protected], and


mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in
the SUGGEST A TITLE form on www.packtpub.com or e-mail [email protected].

If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you
to get the most from your purchase.

4
Preface

Downloading the example code for this book


You can download the example code files for all Packt books you have
purchased from your account at http://www.PacktPub.com. If you
purchased this book elsewhere, you can visit http://www.PacktPub.
com/support and register to have the files e-mailed directly to you.

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be
grateful if you would report this to us. By doing so, you can save other readers from would like
to see. frustration and help us improve subsequent versions of this book. If you find any errata,
please report them by visiting http://www.packtpub.com/support, selecting your book,
clicking on the let us know link, and entering the details of your errata. Once your errata are
verified, your submission will be accepted and the errata will be uploaded on our website, or
added to any list of existing errata, under the Errata section of that title. Any existing errata can
be viewed by selecting your title from http://www.packtpub.com/support.

Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt,
we take the protection of our copyright and licenses very seriously. If you come across any
illegal copies of our works, in any form, on the Internet, please provide us with the location
address or website name immediately, so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected


pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions
You can contact us at [email protected] if you are having a problem with any
aspect of the book, and we will do our best to address it.

5
Other documents randomly have
different content
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like