Pro Javafx Platform.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
THE EXPERT’S VOICE® IN JAVA™ TECHNOLOGY Covers the full JavaFX™™ 1.1. 2 2 platform Pro ™ JavaFX Platform Script, Desktop and Mobile RIA with Java™ Technology James L. Weaver, Weiqi Gao, Ph.D., Stephen Chin, and Dean Iverson Foreword by Danny Coward Chief Architect, Client Software, Sun Microsystems Download at Boykma.Com Pro JavaFX™ Platform Script, Desktop and Mobile RIA with Java™ Technology / First Edition James L. Weaver, Weiqi Gao, Ph.D., Stephen Chin, and Dean Iverson Download at Boykma.Com Pro JavaFX™ Platform: Script, Desktop and Mobile RIA with Java™ Technology Copyright © 2009 by James L. Weaver, Weiqi Gao, Ph.D., Stephen Chin, and Dean Iverson All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-1875-3 ISBN-13 (electronic): 978-1-4302-1876-0 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Java™ and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the US and other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was writ- ten without endorsement from Sun Microsystems, Inc. Lead Editor: Steve Anglin Development Editor: Matthew Moodie Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Richard Dal Porto Copy Editors: Liz Welch, Ami Knox Associate Production Director: Kari Brooks-Copony Production Editor: Kelly Gunther Compositor: Patrick Cunningham Proofreader: Nancy Sixsmith Indexer: Brenda Miller Artist: April Milne Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail kn`ano)ju<olnejcan)o^i*_ki, or visit dppl6++sss*olnejcankjheja*_ki. For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail ejbk<]lnaoo*_ki, or visit dppl6++sss* ]lnaoo*_ki. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at dppl6++sss*]lnaoo*_ki+ejbk+^qhgo]hao. The information in this book is distributed on an “as is” basis, without warranty. Although every precau- tion has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indi- rectly by the information contained in this work. The source code for this book is available to readers at dppl6++sss*]lnaoo*_ki. You may need to answer questions pertaining to this book in order to successfully download the code. Download at Boykma.Com Contents at a Glance Foreword ........................................................................xv About the Authors ................................................................xix Acknowledgments ...............................................................xxiii Introduction .................................................................... xxv CHAPTER 1 Getting a Jump Start in JavaFX ..................................1 CHAPTER 2 Taking a Closer Look at the JavaFX Script Language .............43 CHAPTER 3 Creating a User Interface in JavaFX .............................99 CHAPTER 4 Using Functions, Classes, and Other Advanced Features ........167 CHAPTER 5 Creating Custom UI Components and Charts in JavaFX ..........239 CHAPTER 6 Using the Media Classes .......................................289 CHAPTER 7 Dynamically Laying Out Nodes in the User Interface .............313 CHAPTER 8 Extending JavaFX with Third-Party Libraries ....................367 CHAPTER 9 Building a Professional JavaFX Application .....................449 CHAPTER 10 Developing JavaFX Mobile Applications ........................495 APPENDIX Keywords and Operators ......................................521 INDEX .......................................................................525 iii Download at Boykma.Com Download at Boykma.Com Contents Foreword ........................................................................xv About the Authors ................................................................xix Acknowledgments ...............................................................xxiii Introduction .................................................................... xxv CHAPTER 1 Getting a Jump Start in JavaFX .............................1 JavaFX Can’t Bring Rich-Client Java Back by Itself ....................2 A Brief History of JavaFX ..........................................3 Going to the Source: Sun’s JavaFX Web Sites ........................5 Accessing the JavaFX SDK API ................................6 Obtaining the JavaFX SDK ....................................7 JavaFX Production Suite ......................................7 Other Available Tools .........................................7 Developing Your First JavaFX Program: “Hello Earthrise” ..............8 Compiling and Running from the Command Line .................8 Understanding the Hello Earthrise Program .....................9 Building and Running the Program with NetBeans ..............19 Deploying JavaFX Applications ....................................22 Deploying JavaFX Applications with Java Web Start .............22 Deploying JavaFX Applets ...................................24 Developing Your Second JavaFX Program: “More Cowbell!” ..........27 Building and Running the Audio Configuration Program ..........28 The Behavior of the Audio Configuration Program ...............29 Understanding the Audio Configuration Program ................29 Surveying JavaFX Features .......................................38 Summary .......................................................40 Resources ......................................................41 v Download at Boykma.Com vi NCONTENTS CHAPTER 2 Taking a Closer Look at the JavaFX Script Language ....43 An Overview of JavaFX Script .....................................44 Understanding Variables, Values, and Their Types ...................44 Understanding Variable Names ...............................45 Understanding Variable Types ................................45 Understanding the Primitive Types .................................46 Understanding the Boolean Type .............................46 Understanding the Integer Type ..............................48 Understanding the Character Type ............................50 Understanding the Byte, Short, and Long Types ................51 Understanding the Number Type ..............................52 Understanding the Float and Double Types .....................54 Understanding the String Type ...............................54 Understanding the Duration Type .............................57 Working with Sequences .........................................58 Understanding Sequence Types ..............................58 Constructing Sequences Using Explicit Sequence Expressions ....60 Constructing Numeric Sequences Using Range Expressions ......60 Manipulating Sequences ....................................62 Understanding Sequence Comprehension ......................68 Using Utility Functions in javafx.util.Sequences .................70 JavaFX Script Expressions ........................................73 Understanding Expressions and Their Types ...................73 Understanding the Block Expression ..........................74 Understanding Precedence and Groupings .....................74 Understanding the Expression Separator .......................75 Understanding Variable and Constant Declarations ..............75 Understanding the Assignment Operator .......................76 Understanding the Compound Assignment Operators ............77 Understanding the Relational Operators .......................78 Understanding the While Expression ..........................80 Revisiting the For Expression .................................81 Understanding the If Expression ..............................82 Understanding Object Literals .....................................84 Understanding Classes and Objects ...........................84 The Object Literal Expression ................................85 Manipulating Objects ........................................87 Creating Java Objects with the new Operator ...................90 The Making of a Declarative Syntax ...........................90 Download at Boykma.Com NCONTENTS vii Working with Data Bindings .......................................91 Understanding the Bind Expression ...........................91 Understanding Bidirectional Bindings and Lazy Bindings .........94 Summary .......................................................97