JavaFX 前言

details 目录

JavaFX 是 Java 的 GUI 工具包(GUI 是图形用户界面的缩写)。 JavaFX 使使用 Java 创建桌面应用程序和游戏变得更加容易。 本 JavaFX 教程是解释 JavaFX 核心功能的多页教程。 请参阅此页面左侧的菜单以查看本 JavaFX 教程中涵盖的所有主题。 此页面下方还有一个额外的资源清单。

JavaFX is a GUI toolkit for Java (GUI is short for Graphical User Interface). JavaFX makes it easier to create desktop applications and games in Java. This JavaFX tutorial is a multi-page tutorial explaining the core features of JavaFX. See the menu in the left side of this page to see all the topics covered in this JavaFX tutorial. There is also an extensive list further down this page.

为什么选择 JavaFX?

JavaFX 是一个出色的 GUI 应用程序平台有几个原因。 首先,Java 仍然是世界上最流行的编程语言之一,拥有大量的标准类(class),以及由 Java 开发者社区开发的丰富的开源工具包。

There are several reasons why JavaFX is a great GUI application platform. First of all, Java is still one of the most popular programming languages in the world, with a large set of standard classes, and a rich set of open source toolkits developed by the Java developer community.

其次,JavaFX 可以在以下所有操作系统和设备上运行:

Second, JavaFX can run on all of the following OS’es and devices:

  • Windows
  • Linux
  • Mac
  • iOS
  • Android / Chromebook
  • 树莓派

这使得 JavaFX 成为一个通用的、跨操作系统和跨设备应用程序工具包。

This makes JavaFX a versatile cross OS and cross device application toolkit.

第三,JavaFX 带有一组丰富的 GUI 控件(control),并且开源工具包为整个 Java 生态系统添加了更多功能。

Third, JavaFX comes with a rich set of GUI controls, and open source toolkits add even more tools to the total ecosystem.

JavaFX 功能

JavaFX 带有大量内置的 GUI 组件,例如按钮、文本字段、表格、树、菜单、图表等等。 JavaFX 可以通过 CSS 和 / 或以编程方式设置样式。 JavaFX 带有一个内置的图表库,您可以将其用于简单图表。 JavaFX 支持 2D 和 3D 图形。 JavaFX 有一个可以显示现代 Web 应用程序的 WebView。

JavaFX comes with a large set of built-in GUI components, like buttons, text fields, tables, trees, menus, charts and much more. JavaFX can be styled via CSS and / or programmatically. JavaFX comes with a built-in chart library you can use for simple charts. JavaFX has support for 2D and 3D Graphics. JavaFX has a WebView which can display modern web applications.

以下是 JavaFX 中更完整的关于概念、组件和功能的列表:

Here is a more complete list of concepts, components and features in JavaFX:

为什么选择开发桌面应用程序(而不是 Web 应用程序)?

为什么移动设备首选原生 / 本地应用程序,而台式计算机首选 Web 应用程序?为什么这两种类型的设备都不首选原生 / 本地应用程序?

Why are native / local apps preferred for mobile devices - but web apps preferred for desktop computers? Why are native / local apps not preferred for both types of devices?

原生 / 本地应用程序往往比 Web 应用程序提供更好的用户体验,因为它响应速度更快、更敏捷、具有更高级的 GUI 控件以及更好地与本地设备集成。传统桌面应用程序的两个最大问题是网速慢导致下载慢以及安装过程繁琐。随着高速互联网连接的普及,个人设备的应用商店和企业机器的预装,这两个问题都已基本解决。

Native / local apps tend to provide a better user experience than web apps by being more responsive (faster, snappier), having more advanced GUI controls, and by better integrating with the local device. The two biggest problems for traditional desktop apps was low Internet bandwidth and a cumbersome installation process. Both of these problems have pretty much been resolved with high speed Internet connections being quite common, and with app stores for private devices and install-on-demand systems for corporate machines.

在我看来,对于所有经常使用的应用程序或工作流程有些复杂的应用程序,应该首选原生 / 本地应用程序。对于需要访问其运行的计算机的本地磁盘,或者需要与许多不同的远程系统通信,有时使用 HTTP 以外的其他协议(例如 IAP 或流协议等)的应用程序,原生 / 本地应用程序也应该是首选。有关更多应用程序示例,请参阅 JavaFX 用例。

In my opinion native / local apps should be preferred for all apps that are being used often, or where the workflow is somewhat complicated. Native / local apps should also be preferred for applications that need to access the local disk of the computer it runs on, or which needs to communicate with many different remote systems, and sometimes using other protocols than HTTP (e.g. IAP or streaming protocols etc.). See JavaFX use cases for more application examples.

用户很少使用的应用程序,或者用户没有真正动机下载和安装的应用程序可能应该保留为 Web 应用程序。例如,用于登录和管理您的保险合同的应用程序可能可以作为 Web 应用程序来实施。但是,您的用户每天使用多次的项目管理工具可能最好是桌面应用程序。

Apps the user use rarely, or which the user is not really motivated to download and install should probably remain as web apps. For instance, an app to login in and administer your insurance contracts is probably fine to implement as as a web app. But a project management tool that your users are using several times per day is probably better off being a desktop app.