28,79 €
If you are a Java developer, an experienced Java Swing, Flash/Flex, SWT, or web developer looking to take your client-side applications to the next level, this book is for you.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 220
Veröffentlichungsjahr: 2015
Copyright © 2015 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: June 2015
Production reference: 1250615
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-802-6
www.packtpub.com
Author
Mohamed Taman
Reviewers
Sergey Grinev
José Pereda
Commissioning Editor
Amarabha Banerjee
Acquisition Editor
Aaron Lazar
Content Development Editor
Sumeet Sawant
Technical Editor
Naveenkumar Jain
Copy Editors
Roshni Banerjee
Aditya Nair
Adithi Shetty
Project Coordinator
Shweta Birwatkar
Proofreader
Safis Editing
Indexer
Hemangini Bari
Graphics
Sheetal Aute
Production Coordinator
Nitesh Thakur
Cover Work
Nitesh Thakur
Mohamed Taman, chief of architects and software development manager at e-finance, lives in Cairo, Egypt. He graduated in electrical engineering from Faculty of Engineering, Cairo University. He is an experienced Java developer who has worked on the Web, mobile, and IoT for industries, including finance, banking, tourism, government, and healthcare. Before that, he worked with Pfizer, Intercom Enterprise (a Gold IBM partner), Silicon Expert, and Oracle using varied technologies, such as user-facing GUI frontends, backends, mid-tiers, and integrations of large-scale systems.
He enjoys speaking at many conferences evangelizing Java standards and his experience worldwide, as he is a strong Java community member and a Java Champion since 2015.
In addition, Mohamed is a member of Adopts Java EE 8, OpenJDK, and JavaFX programs. He was an executive member of Java Community Process Organisation, being the first African to join its board.
He is also a member of the expert group JSR 354, 363, and 373. He is also the leader of EGJUG and MoroccoJUG member, a board member of Oracle Egypt Architects Club. He won the 2014 Duke’s choice and 11th annual JCP adopt 2013 awards.
You can read more about the author at http://about.me/mohamedtaman.
Sergey Grinev is an experienced software development and QA engineer focused on building reliable quality processes for Java platforms. He started to work in this area during his employment with Oracle, where he was responsible for JavaFX quality. Since the past few years, he has been working for Azul Systems on the quality of their custom JVMs.
Also, Sergey enjoys teaching people, presenting on various Java conferences, giving lessons, and answering Java-related questions on http://stackoverflow.com.
He graduated from St. Petersburg State University and currently resides in St. Petersburg, Russia.
José Pereda has done his PhD in structural engineering and works as an assistant professor in the School of Industrial Engineering at the University of Valladolid in Spain. His passion lies in applying programming to solve real problems. Working with Java since 1999, he is now a JavaFX advocate, developing commercial applications and open source projects (JFXtras, FXyz, https://github.com/jperedadnr), coauthoring a JavaFX book (JavaFX 8 Introduction by Example), blogging (http://jperedadnr.blogspot.com.es/), tweeting (@JPeredaDnr), and speaking at conferences (JavaOne, JAX, Jfokus, JavaLand, and so on). José lives with his wife and kids in Valladolid, Spain.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
This book, as its title (JavaFX 8 Essentials) suggests, is a pragmatic book that provides you with a robust set of essential skills that will guide you to become confident enough to rapidly build high-performance JavaFX 8 client applications. These applications take advantage of modern GPUs through hardware-accelerated graphics while delivering a compelling, complex, and fancy rich-client GUI for your customer, which will impress them quite a bit.
Learning the JavaFX 8 essentials is the first step to plunging into creating applications that most importantly run on any platform, from the desktop, Web, mobile, tablets, to embedded devices such as Arduino, Raspberry Pi, and multi-core development. Following Java's Write once, run anywhere paradigm, JavaFX also preserves the same. Because JavaFX 8 is written totally from scratch in the Java language, you will feel at home.
Most of the chapters are a fast-paced guide that will help you get a head start on Java GUI programming, leveraging JavaFX 8 and deploying and running on any platform.
While working through the book examples, you will find code is written with JavaFX 8 on Java 8 (yes, Java SE 8) so that the new APIs and language enhancements will help you become a more productive developer. Having said this, it will be handy (and I encourage you to go for this) to explore all of the new Java 8 capabilities.
Finally, yet importantly, you will be able to develop amazing touch-less interactive motion applications with JavaFX that interact with Leap motion devices.
Chapter 1, Getting Started with JavaFX 8, is an introduction to JavaFX 8. It discusses JavaFX 8 as a technology, why you should care about it, its history, core features, and where it can be used.
So it is time to get ready with the right tools and go through the necessary steps to install JavaFX 8 and its supporting development tools. Learn about additional tools that will increase reader productivity in this chapter. As a final verification that we are on the right track, we are going to close the chapter with a simple Hello JavaFX application.
Chapter 2, JavaFX 8 Essentials and Creating a Custom UI, discusses how there is nothing more frustrating than receiving complicated advice as a solution to a problem. Because of this, I have always made it a point to focus on the essentials. In order to render graphics on the JavaFX scene, you will need a basic application, scene, canvas, shapes, text, controls, and colors.
Also, you will learn about JavaFX 8 essential application structures that serve as a backbone to any future application. And finally, we will also explore some Java SE 8 features (such as Lambda, Streams, JavaFX Properties, and so on) to help increase code readability, quality, and productivity.
After getting hands-on experience in creating a structured JavaFX 8 application, wouldn't it be nice if you could change the UI of your application without altering its functionality? In this chapter, you will learn about theming and how to customize applications by applying various themes (look and feel) and the fundamentals of JavaFX CSS styling.
You will use Scene Builder to create and define UI screens graphically and save them as a JavaFX FXML-formatted file. Finally, you will learn about creating custom controls.
Chapter 3, Developing a JavaFX Desktop and Web Application, covers on how to develop a compelling desktop and Web application that takes advantage of multi-core hardware accelerated GPUs to deliver a high performance UI-based application with an amazing appearance.
As JavaFX is totally written from the ground up in Java, some Java SE 8 built-in core libraries will be used to power our application. Also, you will learn how to package your application as a standalone application to be launched and distributed.
In addition, we will cover the essential core web APIs in any web application levered by JavaFX 8, such as javafx.scene.web.WebEngine and javafx.scene.web.WebView.
We will also discuss the relationship between JavaFX and HTML5, which is important because they complement each other. JavaFX's rich client APIs, coupled with HTML5's rich web content, create a user experience resembling a RIA Web application with the characteristics of native desktop software.
Chapter 4, Developing a JavaFX Application for Android, as we see a rise in non-pc clients, mobile phones and tablets are gaining market share. JavaFX 8 can deliver a rich client application for Web and desktop. If you write a JavaFX application, make sure you want it to run on as many devices as possible. This chapter will give you essential hands-on experience and knowledge about SDKs that allow users to create native applications for Android mobile phones.
Chapter 5, Developing a JavaFX Application for iOS, is an extension to the previous chapter. If you write a JavaFX application for Android, be sure you want it to run on as many iOS devices as possible. This chapter will give you essential hands-on experience and knowledge about SDKs that allow them to create native applications for Apple iOS.
Chapter 6, Running JavaFX Applications on the Raspberry Pi, will provide you with all the necessary skills and knowledge to develop a JavaFX 8 application that runs on a credit card-sized computer, the Raspberry Pi board. As the Internet of things (IoT) has become a hot topic of late. Java was made for the Internet of things literally.
Chapter 7, Monitoring and Controlling Arduino with JavaFX, covers another kind of Internet of everything (IoT). Arduino is an open-source electronics prototyping platform, delivering low-cost prototyping platforms to support both the do-it-yourself concept and the maker movement.
This chapter will provide you with all the necessary skills and knowledge to quickly use JavaFX along with an Arduino board to develop desktop applications for monitoring data coming from the real world or controlling real devices.
Chapter 8, Interactive Leap Motion Apps with JavaFX, will make you learn about gesture recognition. You will discover an awesome gadget, the Leap Motion device, which will allow a touch-less approach to develop enhanced JavaFX applications.
Machine user input interfaces are becoming increasingly less mouse-centric, in favor of multi-touch and even touch-less input. Gestures are one of the ways humans can communicate with machines naturally these days.
Appendix, Become a JavaFX Guru, will make you find many useful links and references that will help you gain further knowledge about all things JavaFX.
At the end of this chapter, make sure to check out the many frameworks, libraries, and projects that use JavaFX in production today.
The examples given in this book utilize the latest release of Java SE 8 at the time of writing, namely the Java SE 8 update 45 JDK edition. Starting with Java SE 8, it comes pre-bundled with the JavaFX 8 that we use throughout this entire book. Also, NetBeans IDE version 8.0.2 is used as an Integrated Development Environment, as well as the JavaFX designer tool Gluon Scene Builder version 8, as general software and tools.
As each chapter is unique in its nature and requires specific software and hardware for the JavaFX 8 examples to run normally, this book provides all the required software, tools, and hardware with detailed explanation on how to install and configure them, in order to run JavaFX 8 examples smoothly.
If you are a Java developer, an experienced Java Swing, Flash/Flex, SWT, or a web developer looking to take your client-side applications to the next level, this book is for you. This book will put you on the right track to begin creating a fancy, customizable, and compelling user interface.
Also, you will learn how to create high-performance rich client-side applications rapidly that run on any platform, be it desktop, web, mobile, or embedded systems, such as Raspberry Pi, Arduino, and applications based on the touch-less Leap Motion.
This book is a fast-paced guide that will help you get a head start on Java GUI programming leveraging JavaFX 8, deployed and runs on any platform.
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, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."
A block of code is set as follows:
Any command-line input or output is written as follows:
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: "Click on Install to begin the installation".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
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 get the most out of.
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 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.
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.
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.
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/8026OS_ColorImages.pdf.
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 frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form 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 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.
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.
JavaFX is Java's next-generation Graphical User Interface (GUI) toolkit. It's a platform that makes it easy to rapidly build high-performance Java client-side applications.
JavaFX's underlying engines take advantage of modern GPUs through hardware-accelerated graphics, while providing well-designed programming interfaces, thus enabling developers to combine graphics, animation, and UI controls.
These capabilities allow you to deliver a compelling, complex, and fully customizable client GUI for your customer that will make them quite impressed.
While the original targets of Java were the embedded and client worlds, since 2006, many reasons pushed the Java language to become the top development platform for the Enterprise world.
But recently, with the JavaFX platform's entrance as the standard client GUI, those original targets have started to gain popularity again.
Although it is much more than just a GUI toolkit, JavaFX allows Java developers to create client applications with compelling user interfaces that easily connect to backend systems.
In addition, JavaFX's flexible FXML support allows you to build MVC (Model-View-Controller) architectural pattern applications easily, and use the WYSIWYG approach using the Scene Builder tool.
JavaFX's bindings feature simplified communication between entities and support MVC even further. In addition to that, JavaFX provides fast, customizable UI modeling using CSS.
By adding a full-fledged WebView component with a document model, mapping to Java code is easy and provides great support for 3D and media capabilities.
In this chapter, we are going to cover the following topics:
JavaFX came to light with a primary goal – to be used across many types of devices, such as embedded devices, smartphones, TVs, tablet computers, and desktops. JavaFX also follows Java's write once, run anywhere paradigm.
JavaFX 8 is written totally from scratch in Java language, it makes you feel at home. Therefore, applications written in JavaFX can be deployed on desktops, laptops, the Web, embedded systems, mobiles, and tablets.
Embedded systems are no longer supported by Oracle; it is left to companies like ARM and others to support it. Mobile devices have never been supported from JavaFX 2.x to 8.x; the support exists now only because of OpenJFX. The community has benefitted from open source bringing JavaFX to mobile environments.
For more about OpenJFX, visit https://wiki.openjdk.java.net/display/OpenJFX/Main.
JavaFX is a set of graphics and a media package that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms, in one bundle, without the need for many separate libraries, frameworks, and APIs to achieve the same goal. These separate libraries include media, UI controls, WebView, 3D, and 2D APIs.
So if you are a Java frontend developer, an experienced Java Swing, Flash/Flex, SWT, or web developer looking to take your client-side applications to the next level, and you want to develop an attractive and complex user interface for your customer, then you are on track learning JavaFX skills – this book is for you.
This chapter is an introduction to JavaFX 8; we have already talked about JavaFX 8 as a technology and why you should care about it.
Next, we will navigate its history, exploring its core features and where it could be used.
Before you start using this book to learn JavaFX 8, we will go through the preparation of your development environment by installing various required software bundles, to be able to compile and run many of its examples.
In this chapter, you will learn how to install the required software, such as theJava Development Kit JDK and the NetBeans Integrated Development Environment (IDE).
After installing the required software, you will begin by creating a traditional Hello JavaFX 8 example. Once you feel comfortable with the development environment, as a final verification that we are on the right track, we will walk through the Hello JavaFX 8 source code to understand the basic JavaFX 8 application architecture.
If you are already familiar with the installation of the JDK and the NetBeans IDE, you can skip to Chapter 2, JavaFX 8 Essentials and Creating a custom UI, which covers JavaFX 8 fundamentals and how to create a custom UI component.
So what you are waiting for? Let's get started!
You