Getting started with JavaFX 2 Introduction by Example Book
If you’ve purchased the book “JavaFX 2.0 Introduction by Example” and recently obtained the code from the book’s site you will noticed that some of the examples don’t work quite like they used to. That’s because of the time of the writing of the book I was using preview editions leading up to JavaFX 2.0 GA (API changes & bug fixes). To get the latest code you’ve come to the right place. If you haven’t purchased the book I encourage you to head on over to your favorite bookstore to get yourself a copy (Amazon, Barnes&Noble, Apress).
On this page I will provide instructions for the most popular IDEs (NetBeans, Eclipse, and IntelliJ) and the latest and greatest of the book’s source code examples. This page is a work in progress. Having said that I currently (only) have instructions for the NetBeans 7.2 IDE shown below. As time goes by I will continue to update this site with instructions for the other IDEs listed. The book also details on how to use the command line to compile and run the examples.
- Java 7 u6 or greater (includes JavaFX 2.2)
- JavaFX 2.2 or greater
- NetBeans 7.2 or greater
- Book source code (GitHub)
- Derby database
- Download Java 7 update 6 which includes JavaFX 2.2 from Oracle: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Read license agreement and click on the accept (radio button) button
- Download the JDK that’s based on your operating system (OS)
- After the download you will launch the installer
- Click Next which then proceeds with a progress bar preparing the installation process.
- You are presented the location to install. Shown below is the Java home or default on the Windows platform. Just click Next.
- Successful Installation window. Click the close to finish.
- Download NetBeans 7.2 from: http://netbeans.org/downloads/index.html
- After download launch the installer
- Click Next
- Accept the terms of the license agreement after you have read it. Click on check box then click on the Next button.
- Do the same for the JUnit license agreement and click Next
- Choose the installation folder and JDK by clicking on the browse button to locate a destination directory. Shown below are the defaults for Windows operating system (C:\Program Files\NetBeans 7.2). You’ll notice that it picks up the latest JDK 7 that was installed. Click on the Next button.
- Proceed by clicking the Install button shown below:
- The installation process is underway. Shown below is the progress dialog:
- Once it is completed you will get a dialog message showing that you succeeded. You should now be ready to launch the NetBeans IDE. Shown below is the newly installed application in the start menu of the Windows platform:
- Select the NetBeans IDE 7.2 Icon to launch.
- Once started you should see the main menu options and the start page tab is displayed.
- Download the book’s NetBeans source code project (zip file). You can download the zip file from the GitHub https://github.com/carldea/JavaFX2IntroByExampleCode/blob/master/netbeans/NetBeans-JavaFX2IntroByExampleAppSampler-20120904.zip?raw=true
Most browsers you will simply right click and ‘Save as link As‘ to a file to be downloaded.
- Import the zip file into the NetBeans IDE. On the menu select ‘File -> Import Project -> From Zip’. Depicted below is the import zip options:
- Locate the book’s zip file recently downloaded. Click the top Browse button to locate file.
- Select the zip file to be imported and click on the open button. Shown below is the File chooser to import zip file:
- You’ll return to the dialog showing the import dialog window with the zip file path and the project destination directory.
- After clicking on Import you should see the project on the left side of the IDE (project tab). Now click on the Green triangle on the tool bar to run the App Sampler Application to run all the examples.
- After launching the application you should see the application depicted below:
- To launch the examples double click a recipe in the table view of one of the chapter tabs.
*NOTES: derby.jar and derbytools.jar need to be included in the IDE’s classpath to run one of the examples (RSS feed reader). The example will still work if the jars aren’t referenced, you just won’t have RSS links saved when you relaunch the example.
Now that you have successfully installed and able to run the code you will be a JavaFX Ninja in no time! If you have any question don’t hesitate to leave me a comment.