Javafx 简明教程

JavaFX - Installation Using Netbeans

Apache Netbeans 是使用 Java 开发应用程序的免费开源集成开发环境 (IDE)。它允许您使用 JavaFX 创建应用程序。

Apache Netbeans is a free and open source integrated development environment (IDE) to develop applications using Java. And it allows you to create applications using JavaFX.

本章演示如何使用 Netbeans 创建 JavaFX 应用程序。我们将安装 JavaFX SDK 和 Apache Netbeans 的最新版本。

This chapter demonstrates how to create a JavaFX application in Netbeans. We will be installing the latest versions of both JavaFX SDK and Apache Netbeans.

Setting NetBeans Environment of JavaFX

NetBeans18 提供对 JavaFX 的内置支持。安装完成后,您无需任何其他插件或 JAR 文件即可创建 JavaFX 应用程序。要设置 NetBeans 环境,您需要按照下面给出的步骤操作。

NetBeans18 provides inbuilt support for JavaFX. On installing this, you can create a JavaFX application 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 − 访问 NetBeans website NetBeans 网站,然后单击下载按钮以下载 NetBeans 软件。

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

netbeans download page

Step 2 − 单击此按钮后,将下载名为 Apache-NetBeans-18-bin-windows-x64.exe 的文件到您的系统上。运行此文件以安装它。运行此文件后,NetBeans 安装程序将启动,如下面的屏幕截图所示。

Step 2 − On clicking this button, a file named Apache-NetBeans-18-bin-windows-x64.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.

配置完成后,您将看到 Welcome Page of the installer

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

Step 3 − 单击 Next 按钮,然后继续安装。

Step 3 − Click the Next button and proceed with the installation.

netbeans ide installer

Step 4 − 下一个窗口包含 NETBEANS IDE 18 license agreement 。仔细阅读并选中“我接受许可协议中的条款”复选框以接受协议,然后单击 Next 按钮。

Step 4 − The next window holds the NETBEANS IDE 18 license agreement. Read it carefully and accept the agreement by checking the checkbox at “I accept the terms in the license agreement” and then click the Next button.

netbeans license agreement

Step 5 − 选择需要安装 Netbeans 18 的目标目录。此外,您还可以浏览 Java Development Kit 已安装在您的系统中的目录,并单击 Next 按钮。

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

netbeans installation next

Step 6 − 选中 Check for Updates 框以自动更新,然后单击 Install 按钮开始安装。

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

click install button

Step 7 − 之后向导将开始准备安装数据。

Step 7 − The wizard will then start preparing the installation data.

Step 8 − 此步骤将开始安装 NetBeans IDE 18 并且可能需要一段时间。

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

Step 9 − 流程完成后,单击 Finish 按钮完成安装。

Step 9 − Once the process is complete, click the Finish button to finish the installation.

installation finish

Step 10 − 启动 NetBeans IDE 后,您将看到如以下屏幕截图所示的开始页面。

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

start page

Step 11 − 在文件菜单中,选择 New Project … 以打开新建项目向导,如以下屏幕截图所示。

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

netbeans file

Step 12 − 在 New Project 向导中,选择 Java with Ant 并单击 Next 。它会开始为您创建新的 Java 应用程序。

Step 12 − In the New Project wizard, select Java with Ant and click on Next. It starts creating a new Java Application for you.

new project select java

Step 13 − 在 New Java Application 窗口中选择项目名称和项目位置,然后单击 Finish 。它将创建具有给定名称的示例应用程序。

Step 13 − Select the name of the project and location of the project in the New Java Application window and then click Finish. It creates a sample application with the given name.

sample java application

在此示例中,将创建一个名称为 SampleJavaApplication 的应用程序。在此应用程序内,NetBeans IDE 将生成一个名为 SampleJavaApplication.java 的 Java 程序。如以下屏幕截图所示,此程序将在 NetBeans 源包 → samplejavaapplication 中创建。

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

samplejavaapplication java

Step 14 − 右键单击该文件并选择 Run Project 以运行此代码,如以下屏幕截图所示。

Step 14 − Right-click on the file and select Run Project to run this code as shown in the following screenshot.

runproject

此自动创建的程序包含生成简单 JavaFX 窗口的代码,该窗口中有一个带有标签 Say ‘Hello World’ 的按钮。每次单击此按钮时,字符串 Hello World 都将显示在控制台上,如下所示。

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 click on this button, the string Hello World will be displayed on the console as shown below.

say hello world

Note − 我们将在后面的章节中学习代码。

Note − We will learn about the code in further chapters.