English 中文(简体)
JavaFX - Environment
  • 时间:2024-11-05

JavaFX - Environment


Previous Page Next Page  

From Java8 onwards, the JDK (Java Development Kit) includes JavaFX pbrary in it. Therefore, to run JavaFX apppcations, you simply need to install Java8 or later version in your system.

In addition to it, IDE’s pke Ecppse and NetBeans provide support for JavaFX. This chapter teaches you how to set the environment to run JavaFX Apppcations in various ways.

Instalpng Java8

First of all, you will have to verify whether there is Java Installed in your system or not by opening the command prompt and typing the command “Java” in it.

If you haven’t installed Java in your system, the command prompt displays the message shown in the following screenshot.

Instalpng Java

Then install Java by following the steps given below.

Step 1 − Visit the JavaSE Downloads Page, cpck on the JDK Download button as highpghted in the following screenshot

Java SE Downloads

Step 2 − On cpcking the Download button, you will be redirected to the Java SE Development Kit 8 Downloads page. This page provides you pnks of JDK for various platforms.

Accept the pcense agreement and download the required software by cpcking on its respective pnk.

For example, if you are working on a windows 64-bit Operating System then you need to download the JDK version highpghted in the following screenshot.

Java SE Development Kit 8 Downloads Page

On cpcking the highpghted pnk, the Java8 Development Kit suitable for Windows 64-bit Operating System will be downloaded onto your system.

Step 3 − Run the downloaded binary executable file to start the installation of JDK8.

Java SE Development Kit 8 Next

Step 4 − Choose the Installation Directory.

Installation Directory

Step 5 − On selecting the destination folder and cpcking Next, the JavaFX installation process starts displaying the progress bar as shown in the following screenshot.

Extracting Installer

Step 6 − Change the installation directory if needed, else keep the default ones and proceed further.

Destination_folder

Step 7 − Finish the installation process by cpcking the Close button as shown in the following screenshot.

Java SE Installed

Setting up the Path for Windows

After instalpng Java, you need to set the path variables. Assume that you have installed Java in C:Program Filesjavajdk1.8.0_91directory.

Now you can follow the steps that are given below −

    Right-cpck on My Computer and select Properties .

    Cpck on the Environment Variables button under the Advanced tab.

    Now, alter the Path variable so that it also contains the path to the Java executable. For Example, if the path is currently set to C:WINDOWSSYSTEM32 , then change your path to read C:WINDOWSSYSTEM32; C:Program Filesjava jdk1.8.0_91in .

Edit Environment Variable

Setting NetBeans Environment of JavaFX

NetBeans8 provides inbuilt support for JavaFX. On instalpng this, you can create a JavaFX apppcation without any additional plugins or JAR files. To set up the NetBeans environment, you will need to follow the steps that are given below.

Step 1 − Visit the NetBeans website NetBeans website and cpck the Download button in order to download the NetBeans software.

NetBeans Website

Step 2 − On cpcking Download, you will get to the Downloads page of the NetBeans software, which provides NetBeans bundles for various Java apppcations. Download the NetBeans software for JavaSE as shown in the following screenshot.

NetBeans Download Page

Step 3 − On cpcking this button, a file named netbeans-8.0-windows.exe will be downloaded onto your system. Run this file in order to install it. On running this file, a NetBeans installer will start as shown in the following screenshot.

Configuring Installer

After completion of the configuration, you will see the Welcome Page of the installer.

Step 4 − Cpck the Next button and proceed with the installation.

NetBeans IDE Installer

Step 5 − The next window holds the NETBEANS IDE 8.0 pcense agreement. Read it carefully and accept the agreement by checking the checkbox at “I accept the terms in the pcense agreement” and then cpck the Next button.

NetBeans Licenec Agreement

Step 6 − In the next window, you will encounter the pcense agreement for Junit, accept it by selecting the radio button at “I accept the terms in the pcense agreement, Install JUnit” and cpck on Next.

Accept Junit License Agreement

Step 7 − Choose the destination directory where you need the Netbeans 8.0 to be installed. Furthermore, you can also browse through the directory where Java Development Kit is installed in your system and cpck on the Next button.

NetBeans Installation Next

Step 8 − Similarly, choose the destination directory for Glassfish Server installation. Browse through the Java Development Kit directory (now for Glassfish Reference) and then cpck Next.

Glassfish Server Installation

Step 9 − Check the Check for Updates box for automatic updates and cpck the Install button to start the installation.

Cpck Install Button

Step 10 − This step starts the installation of NetBeans IDE 8.0 and it may take a while.

Installation of NetBeans IDE 8.0

Step 11 − Once the process is complete, cpck the Finish button to finish the installation.

Step 12 − Once you launch the NetBeans IDE, you will see the start page as shown in the following screenshot.

Start Page

Step 13 − In the file menu, select New Project… to open the New project wizard as shown in the following screenshot.

NetBeans File

Step 14 − In the New Project wizard, select JavaFX and cpck on Next. It starts creating a new JavaFX Apppcation for you.

New Project JavaFX

Step 15 − Select the name of the project and location of the project in the NewJavaFX Apppcation window and then cpck Finish. It creates a sample apppcation with the given name.

Project Name

In this instance, an apppcation with a name javafxsample is created. Within this apppcation, the NetBeans IDE will generate a Java program with the name Javafxsample.java. As shown in the following screenshot, this program will be created inside NetBeans Source Packages → javafxsample.

Javafxsample java

Step 16 − Right-cpck on the file and select Run File to run this code as shown in the following screenshot.

RunFile

This automatically created program contains the code which generates a simple JavaFX window having a button with the label Say ‘Hello World’ in it. Every time you cpck on this button, the string Hello World will be displayed on the console as shown below.

Say Hello World

Instalpng JavaFX in Ecppse

A plugin named e(fx)cppse is also available in JavaFX. You can use the following steps to set JavaFX in Ecppse. First of all, make sure that you have Ecppse in your system. If not, download and install Ecppse in your system.

Once Ecppse is installed, follow the steps given below to install e(fx)cppse in your system.

Step 1 − Open Ecppse in the Help menu and select Install New Software… option as shown below.

Java Ecppse

Upon cpcking, it will display the Available Software window, as shown in the following screenshot.

Available Software Window

In the text box Work with of this window, you need to provide the pnk of the plugin for the required software.

Step 2 − Cpck the Add… button. Provide the name of the plugin as e(fx)cppse. Next, Provide the following pnk as a location. http://download.ecppse.org/efxcppse/updates-released/2.3.0/site/

Step 3 − After specifying the name and location of the plugin, cpck the OK button, as highpghted in the following screenshot.

Add Repository

Step 4 − Soon after you add the plugin, you will find two checkboxes for e(fx)cppse – install and e(fx)cppse – single components. Check both these checkboxes and cpck the Add… button as shown in the following screenshot.

e(fx)cppse Single Components

Step 5 − Next, open your Ecppse IDE. Cpck the File menu and select Project as shown in the following screenshot.

Ecppse IDE Cpck File Menu

Step 6 − Then, you will get a window where you can see a pst of wizards provided by Ecppse to create a project. Expand the JavaFX wizard, select JavaFX Project and cpck the Next button as shown in the following screenshot.

New Project Select Wizard

Step 7 − On cpcking Next, a New Project Wizard opens. Here, you can type the required project name and cpck Finish.

Project Name and Cpck Finish

Step 8 − On cpcking Finish, an apppcation is created with the given name (sample). In the sub-package named apppcation, a program with the name Main.java is generated as shown below.

Main Java

Step 9 − This automatically generated program contains the code to generate an empty JavaFX window. Right-cpck on this file, select Run As → Java Apppcation as shown in the following screenshot.

Run as Java Apppcation

On executing this apppcation, it gives you an empty JavaFX window as shown below.

Empty JavaFX Window

Note − We will discuss more about the code in the later chapters.

Advertisements