JavaFX 1.2 Application Development Cookbook doc - Pdf 12

www.it-ebooks.info

JavaFX 1.2 Application
Development Cookbook
Over 80 recipes to create rich Internet applications with
many exciting features
VladimirVivien
BIRMINGHAM - MUMBAI
www.it-ebooks.info
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])

Melwyn D'sa
www.it-ebooks.info
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,
nancial, 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 ofce for hours to nish 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

Lately, however, his attention has been completely directed towards the simplication 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):
f Google Web Toolkit
f Spring Web Flow 2
f Spring Persistence with Hibernate
Gaga tu sei qui. Ah tu non fuggi. Tu mi risponderai no 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.
www.it-ebooks.info
www.it-ebooks.info
www.it-ebooks.info
This book is dedicated to my son MJV: his smile is my daily inspiration.
www.it-ebooks.info
www.it-ebooks.info

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Reection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lestoapplystyles 148
SkinningapplicationswithmultipleCSSles 152
Chapter5:JavaFXMedia 157
Introduction 157
Accessingmediaassets 158
LoadinganddisplayingimageswithImageView 159

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les 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
www.it-ebooks.info
www.it-ebooks.info
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 t
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

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.
www.it-ebooks.info
Preface
3
What you need for this book
f JavaFX SDK 1.2
ff Java Development Kit (JDK)
ff NetBeans or Eclipse
f 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

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.
www.it-ebooks.info
Preface
5
Downloading the example code for this book
You can download the example code les for all Packt books you have
purchased from your account at http://www.PacktPub.com. If you

f Setting up JavaFX for the NetBeans IDE
f Setting up JavaFX for the Eclipse IDE
f Using javafxc to compile JavaFX Code
f Creating and using JavaFX classes
f Creating and using variables in JavaFX
f Using binding and triggers to update variables
f Creating and using JavaFX functions
f Integrating your JavaFX code with Java
f Creating and using JavaFX sequences
f Working with JavaFX string
Introduction
Today, in the age of Web 2.0, AJAX, and the iPhone, users have come to expect their applications
to provide a dynamic and engaging user interface that delivers rich graphical content, audio,
and video, all wrapped in GUI controls with animated cinematic-like interactions. They want
their applications to be connected to the web of information and social networks available
on the Internet.
www.it-ebooks.info
Getting Started with JavaFX
8
Developers, on the other hand, have become accustomed to tools such as AJAX/HTML5
toolkits, Flex/Flash, Google Web Toolkit, Eclipse/NetBeans RCP, and others that allow them
to build and deploy rich and web-connected client applications quickly. They expect their
development languages to be expressive (either through syntax or specialized APIs) with
features that liberate them from the tyranny of verbosity and empower them with the ability
to express their intents declaratively.
The Java proposition
During the early days of the Web, the Java platform was the rst to introduce rich content
and interactivity in the browser using the applet technology (predating JavaScript and even
Flash). Not too long after applets appeared, Swing was introduced as the unifying framework
to create feature-rich applications for the desktop and the browser. Over the years, Swing

The JavaFX software development kit (SDK) is a set of core tools needed to compile, run, and
deploy JavaFX applications. If you feel at home at the command line, then you can start writing
code with your favorite text editor and interact with the SDK tools directly. However, if you want
to see code-completion hints after each dot you type, then you can always use an IDE such as
NetBeans or Eclipse to get you started with JavaFX (see other recipes on IDEs). This section
outlines the necessary steps to set up the JavaFX SDK successfully on your computer. These
instructions apply to JavaFX SDK version 1.2.x; future versions may vary slightly.
Getting ready
Before you can start building JavaFX applications, you must ensure that your development
environment meets the minimum requirements. As of this writing, the following are the
minimum requirements to run the current released version of JavaFX runtime 1.2.
Minimum system requirements
Windows MacOSX Linux/OpenSolaris
f Windows XP (SP3) or
Windows Vista 32-bit
(all editions)
f Java Development
Kit (JDK) 6 Update
13
f Internet Explorer 6,
Firefox 3.0
f Mac OS X version
10.4.1
f Java Development
Kit (JDK) 5 Update
16
f Safari 3, Firefox 3
f Ubuntu 8.04
f OpenSolaris
2009.06

/Library/Frameworks/JavaFX.framework/Versions/1.2.
Installation on Ubuntu Linux and OpenSolaris
1. Prior to installation, ensure that your Ubuntu or OpenSolaris environment meets the
minimum requirements.
2. Locate the newly downloaded installation package to start installation. For Linux, the
le will end with *-linux-i586.sh. For OpenSolaris, the installation le will end
with *-solaris-i586.sh.
3. Move the le to the directory where you want to install the content of the SDK.
4. Make the le executable (chmod 755) and run it. This will extract the content of
the SDK in the current directory.
5. The installation will create a new directory, javafx-sdk1.2, which is your JavaFX
home location ($JAVAFX_HOME).
6. Now add the JavaFX binaries to your system's $PATH variable,
(export PATH=$PATH:$JAVAFX_HOME/bin).
When your installation steps are completed, open a command prompt and validate your
installation by checking the version of the SDK.
$> javafx -version
$> javafx 1.2.3_b36
www.it-ebooks.info


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status