Javafx 简明教程

JavaFX Tutorial

JavaFX Tutorial

JavaFX 是用于构建富互联网应用程序的 Java 库。使用此库编写的应用程序可以在多个平台上一致地运行。利用 JavaFX 开发的应用程序可在各种设备(如台式机、移动电话、电视、平板电脑等)上运行。

JavaFX is a Java library used to build Rich Internet Applications. The applications written using this library can run consistently across multiple platforms. The applications developed using JavaFX can run on various devices such as Desktop Computers, Mobile Phones, TVs, Tablets, etc.

要使用 Java 编程语言开发 GUI Applications ,程序员依赖于以下之类的库: Advanced Windowing Tool KitSwing 。在 JavaFX 出现之后,这些 Java 编程人员如今可以使用内容丰富的代码有效地开发 GUI 应用程序。

To develop GUI Applications using Java programming language, the programmers rely on libraries such as Advanced Windowing Tool Kit and Swing. After the advent of JavaFX, these Java programmers can now develop GUI applications effectively with rich content.

我们的 JavaFX tutorial 可帮助您以简单易懂的方式学习 JavaFX,以便您可以迅速开始构建您应用程序的用户界面。它涵盖了 JavaFX 的所有必需 UI 元素,以便对 JavaFX 进行从基础到高级的深入理解,并了解 JavaFX 的工作原理。

Our JavaFX tutorial helps you learn JavaFX in simple and easy steps so that you can start building the User Interface of your application quickly. It covers all the necessary UI elements of JavaFX for a basic to advanced understanding of JavaFX and to get a feel of how JavaFX works.

JavaFX Basic UI Controls

JavaFX 提供各种 UI 控件,允许用户与应用程序之间平滑交互。这些控件如下所示:

JavaFx provides a variety of UI controls that allow a smooth interaction between users and applications. These controls are listed below −

S.No

Control & Description

1

Label It is a component for displaying text.

2

Button It is a class used for creating buttons.

3

Menu Contains a list of commands or options.

4

ToolTip A pop-up window that displays some additional information about other UI elements.

5

TextField Accepts and displays user input.

JavaFX Shapes

Shapes 是一款可以在 XY 或 XYZ 平面上绘制的几何图形。建立在 XY 平面上的形状称为 2D 形状,而建立在 XYZ 平面上的形状称为 3D 形状。JavaFx 提供了多种预定义类,可表示不同类型的形状。这些类如下所示:

Shapes are geometric figures that can be drawn on either the XY or XYZ plane. Those built on XY plane are called 2D shapes, while those drawn on XYZ plane are referred to as 3D shapes. JavaFx provides various pre-defined classes that represents different types of shapes. These classes are as follows −

S.No

Class & Description

1

Line It is a class that represents a line. In general, line is a two-dimensional geometrical shape consist of two points.

2

Rectangle It is a class used for creating a 2D rectangular shape. In mathematical terms, rectangle is a four-sided polygon.

3

Box This JavaFX class represents a three-dimensional shape having length, width and height.

4

Cylinder It is a JavaFX class used to create a Cylinder. In general, cylinder is a closed solid figure that has two properties namely radius and height.

JavaFX Effects

在 JavaFx 中, effects 用于增强各种节点的可视外观。JavaFx 中使用的效果列表如下 −

In JavaFx, effects are used to enhance the visual appearance of nodes. The list of effects used in JavaFx are as follows −

S.No

Effect & Description

1

ColorAdjust It is used to apply colour effects to the JavaFx nodes.

2

Blend In this effect, we combine two or more elements to enhance the visuals.

3

Bloom When we apply this effect to any JavaFx node, then some portion of that node will glow.

4

Reflection This effect will add a reflection at the bottom of node.

JavaFX Animations

一般来说, animations 用于对图像、文本、绘图等元素创建特殊视觉效果。JavaFx 中使用最频繁的动画列在下面 −

Generally, animations are used to create special visual effects to the elements like images, text, drawings, etc. The most commonly used animations in JavaFx are listed below −

S.No

Animation & Description

1

Rotate Transition It is used to deal with an object’s position by retaining its shape and properties.

2

Fade Transition This type of animation is done by changing the opacity property of nodes.

3

Stroke Transition It is applied to change the stroke color of a given shape.

4

Scale Transition It is a type animation in which we either increase or decrease the size of an object.

Advantages of JavaFX

与其他 UI 框架(如 Swing 或 AWT)相比,JavaFX 拥有许多优势,例如 −

JavaFX offers many advantages over other UI frameworks, such as Swing or AWT. Some of these advantages are as follows −

  1. JavaFX supports a declarative syntax for defining UI components, called FXML, which can be easily edited by designers or developers.

  2. It supports CSS for styling and animating UI elements, which gives more flexibility and control over the look and feel of the application.

  3. It allows us to use a wide range of media formats, such as images, audio, video, and 3D graphics, which can be integrated seamlessly into the UI.

  4. Since it is a Java based technology, it also has built-in support for concurrency and multithreading, which enables the application to handle complex tasks without blocking the UI thread.

  5. JavaFX also supports binding and properties, which simplifies the communication between the UI and the business logic.

Why to Learn JavaFX?

JavaFX 是一个跨平台且可移植的框架,使开发者可以编写一次应用程序并在支持 Java 的任何平台上运行它。它通过其声明性语法 FXML 和丰富的库集简化了 UI 开发。

JavaFX is a cross-platform and portable framework that allows developers to write an application once and run it on any platform that supports Java. It simplifies UI development with its declarative syntax, FXML, and a rich set of libraries.

我们能通过 CSS 自定义 JavaFX 应用程序。此外,它支持创建动态 UI 效果。作为开源项目,JavaFX 由 Oracle 和庞大的 Java 社区积极开发和维护。

We can customize a JavaFX application through CSS. Additionally, it supports the creation of dynamic UI effects. As an open-source project, JavaFX is actively developed and maintained by Oracle and the huge Java community.

JavaFX 比较容易学,因此如果你开始学习如何开发应用程序的用户界面,那么非常建议你熟悉一下 JavaFX。

JavaFX is fairly easy to learn, so if you are starting to learn how to develop the user interface of an application then it is very much advised that you should also familiarize yourself with JavaFX.

Who Should Learn JavaFX

这个 @[s0] 将帮助学生以及想要开发富 Internet 应用程序的在职专业人员。我们建议按左侧菜单列出的顺序阅读本教程。本教程已经过准备,涵盖从初级到高级的主题。

This JavaFX tutorial will help both students as well as working professionals who want to develop Rich Internet Applications. We recommend reading this tutorial, in the sequence listed in the left-side menu. This tutorial has been prepared to cover topics from beginner to advanced level.

Prerequisites to Learn JavaFX

虽然我们已经尽最大努力以简单易懂的方式编写本 JavaFX 教程,但仍假设读者开始学习本教程中给出的 JavaFX 概念之前已经了解 Java 编程语言。

Though we have tried our best to prepare this JavaFX tutorial in a simple and easy way, still before you start learning JavaFX concepts given in this tutorial, it is assumed that the readers have a prior knowledge of Java programming language.

本教程将通过适当的示例向你传授足够的 JavaFX 多种概念的理解,这样你就能在本教程结束后立即开始你的用户界面开发之旅。

This tutorial will give you enough understanding of the various concepts of JavaFX along with suitable examples so that you can start your User Interface development journey immediately after finishing this tutorial.

JavaFX Jobs and Opportunities

随着对开发丰富且交互式用户界面的需求的增长,精通 JavaFX 的专业人士的需求量很大。许多领先公司正在招聘对 JavaFX 有深刻理解的 IT 专业人员。

Professionals skilled in JavaFX are in high demand as the need to develop rich and interactive user interfaces grows. Many leading companies are recruiting IT professionals with a strong understanding of JavaFX.

JavaFX 专业人士的平均年薪在 3L 到 6L 之间,尽管这可能因你的所在地和经验而异。如果你培养了 JavaFX 技能,你可以应聘各种工作岗位,例如前端开发者、UI 开发者、Java Web 开发者、软件工程师以及更多。你可以在以下公司试着搜索 JavaFX 职位 −

The average annual salary for a JavaFX professional is around 3L to 6L, although this can vary based on your location and experience. If you have developed skills in Javafx, you can apply for various job roles such as Front-end developer, UI developer, Java web developer, Software Engineer and many more. You can try searching for JavaFX jobs in the following companies −

  1. Google

  2. Amazon

  3. JP Morgan

  4. Infosys

  5. TCS

  6. Tech Mahindra

  7. Wipro

  8. Infinizi Consulting Pvt Ltd

  9. Cogniter Technologies

  10. Truechip Solutions

  11. Many more…​

因此,你可能是这些主要公司下一个潜在员工。我们为 JavaFX 开发了出色的学习材料,这将帮助你准备基于 JavaFX 的技术访谈和认证考试。因此,使用我们简单有效的教程随时随地开始学习 JavaFX,绝对按照自己的进度。

So, you could be the next potential employee for any of these major companies. We have developed a great learning material for JavaFX which will help you prepare for the technical interviews and certification exams based on JavaFX. So, start learning JavaFX using our simple and effective tutorial anywhere and anytime absolutely at your pace.

Frequently Asked Questions about JavaFX

有一些关于 JavaFX 的常见问题 (FAQ),本部分尝试简要回答它们。

There are some very Frequently Asked Questions(FAQ) about JavaFX, this section tries to answer them briefly.