JavaFX Script.pdf

(1930 KB) Pobierz
13222108 UNPDF
About firstPress
Apress's firstPress series is your source for understanding cutting-edge technology. Short, highly
focused, and written by experts, Apress's firstPress books save you time and effort. They contain the
information you could get based on intensive research yourself or if you were to attend a conference
every other week––if only you had the time. They cover the concepts and
techniques that will keep you ahead of the technology curve. Apress's firstPress books are real books, in
your choice of electronic or print-on-demand format, with no rough edges even when the technology
itself is still rough. You can't afford to be without them.
JavaFX Script: Dynamic Java Scripting for
Rich Internet/Client-Side Applications
Dear Reader,
JavaFX Script was revealed at JavaOne 2007 as the tool that will enable developers to create rich content
using the JavaFX family of products from Sun Microsystems. I wrote JavaFX Script: Dynamic Java
Scripting for Rich Internet/Client-Side Applications because I am excited about the power and simplic-
ity of using JavaFX Script to create rich internet applications that will run on many different platforms,
including personal computers and mobile phones.
I began developing Java applications in 1995 and have witnessed the capabilities and complexities
of Java increase over time. I recognized the potential in JavaFX Script straight away when I saw how it
can give content designers and application developers a simple, but powerful, language that has all the
capability of Java behind it. For example, in JavaFX Script a simple declarative expression can define a
user interface complete with platform-independent layout managers. Behind-the-scenes, Java facilities
such as layout managers and Swing components are automatically employed to implement the desired
user interface.
My tutorial-style book will have you developing applications with JavaFX Script as quickly as possi-
ble. I lead you step-by-step through JavaFX Script concepts, with each concept building on your
knowledge of the previous one. Exercises and sample solutions test your understanding throughout,
help you learn even faster and, combined with the logical style of the tutorial, also provide a valuable
course textbook or training companion. Complex information on JavaFX Script constructs, such as
operators, are presented in tabular format which makes the book an easy-to-reference guide that you
will turn to again and again. JavaFX Script is very new, and still changing. As it does, this book will be
updated to reflect these changes.
It is my hope that you’ll share my excitement about JavaFX Script and the potential it offers, and
that you’ll enjoy working through the book to reach it.
Regards,
James L. ( Jim) Weaver, SCJD
October, 2007
 
JavaFX Script
Dynamic Java Scripting for Rich
Internet/Client-Side Applications
JAMES L. WEAVER
13222108.026.png
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-Side Applications
Copyright © 2007 by James L. Weaver
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-0554-8
ISBN-10 (pbk): 1-4302-0554-7
Printed and bound in the United States of America (POD)
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trade-
marked 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 United
States and other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written with-
out endorsement from Sun Microsystems, Inc.
Lead Editor: Steve Anglin
Technical Reviewer: Weiqi Gao
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jason Gilmore, Jonathan Hassell,
Chris Mills, Matthew Moodie, Jeffrey Pepper, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Project Manager: Richard Dal Porto
Copy Edit Manager: Nicole Flores
Copy Editor: Damon Larson
Assistant Production Director: Kari Brooks-Copony
Compositor: Richard Ables
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 orders- ny@springer-sbm.com , or visit
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 info@apress.com , or visit http://www.apress.com .
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution 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 indirectly by the information
contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Source Code/
Download section.
 
Contents
Introduction to JavaFX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
The JavaFX Family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
JavaFX Mobile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
JavaFX Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
JavaFX Script's Relationship to Java . . . . . . . . . . . . . . . . . . . . . . . 2
Features and Advantages of JavaFX Script. . . . . . . . . . . . . . . . . . . 2
Current Status of JavaFX Script . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Getting the Most from This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
CHAPTER 2
Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Choosing a JavaFX Development Environment . . . . . . . . . . . . . . . . . . . . 5
Obtaining JavaFXPad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Obtaining an IDE Plug-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The Eclipse Plug-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
The NetBeans Plug-In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Your First JavaFX Application: HelloJFX . . . . . . . . . . . . . . . . . . . . . . . . . 7
Understanding the HelloJFX Application . . . . . . . . . . . . . . . . . . . . . 9
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
The package Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
import Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Declarative Code That Defines the User Interface . . . . . . . . . . . . . 11
Using the Frame Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Creating String Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Using the Canvas GUI Widget . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Drawing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Defining Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Running and Examining the HelloJFXBind Application. . . . . . . . . . . . . . 15
Structure of a Minimal JavaFX Class . . . . . . . . . . . . . . . . . . . . . . 17
The class Declaration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
iii
CHAPTER 1
13222108.027.png
Zgłoś jeśli naruszono regulamin