关于javafx:JavaFX学习笔记二-关键特性与基本概念

42次阅读

共计 9319 个字符,预计需要花费 24 分钟才能阅读完成。

从篇幅上来看前面的控件示例 分成两篇比拟好。

前言

依照我 JavaFX 系列的打算应该是:

  • (一) 介绍基本概念
  • (二) 布局与 UI 控件示例
  • (三) 一个小的桌面零碎
  • (四) JavaFX 打包
  • (四) FXGL(JavaFX 的游戏引擎) 入门与基本概念
  • (五) 罕用示例
  • (六) 小型游戏零碎的构建

以前感觉 JavaFX 的材料少,然而前面在搜索引擎瞎搜,就搜到了 oracle 写的用户领导:

https://docs.oracle.com/javas…

在这个用户领导外面你能够看到 JavaFX 的架构、基本概念、示例都有,甚至我还找到了 Java 8 的官网示例 (JavaFX 和 Java8 的):

https://www.oracle.com/java/t…

认真一看其实官网出的领导还是很清晰的,我大抵对其做了翻译:

  • Getting Started with JavaFX

    • What Is JavaFX

    ​ 什么是 JavaFX?

    • Get Started with JavaFX

    ​ 开启学习 JavaFX 之旅

    • Get Acquainted with JavaFX Architecture

    ​ 相熟 javaFX 的架构

    • Deployment Guide

    ​ 部署指南

  • Graphics (图形化)

    • Getting Started with JavaFX 3D Graphics (3D 图形化)
    • Use the Image Ops API (图片操作 API)
    • Work with Canvas (画布)
  • User Interface Components (UI 组件)

    • Work with UI Controls (应用 UI 组件)

      下拉框、输入框、菜单,JavaFX 都封装好了。

    • Create Charts (创立图表)

    ​ 统计图表

    • Add Text (字体)

    ​ 炫酷字体

    • Add HTML Content (反对 HTML)

      JavaFX 反对内嵌了一个浏览器解析引擎,所以咱们能够在 JavaFX 应用 Web 世界的货色

    • Work with Layouts

      布局, 组件如何摆放

    • Skin Applications with CSS

    ​ 应用 CSS 皮肤

    • Build UI with FXML

      应用 FXML 构建 UI 控件

    • Handle Events

      事件处理

  • Effects, Animation, and Media(动效、动画、音频)

    • Create Visual Effects (制作直观动效)
    • Add 2D & 3D Transformations (2D、3D 变换)
    • Add Transitions & Animation (过渡动画)
    • Incorporate Media(集成媒体)
  • Application Logic(应用逻辑)

    • Work with the Scene Graph(应用 Scene graph)
    • Use Properties and Binding(应用属性和绑定)
    • Work with Collections(应用汇合框架)
  • Interoperability (交互性)

    • Use Concurrency and Threads (并发与线程)
    • Integrate JavaFX and Swing (JavaFx 和 Swing 集成)
    • Integrate JavaFX and SWT(JavaFX 和 SWT 集成)
  • Reference (援用)

    • JavaFX API Documentation (JavaFX 接口文档)
    • CSS Reference Guide (CSS 援用指南)
    • Introduction to FXML (FXML 简介)

兑换成脑图,这份用户领导也相当清晰:

我的评估是这份用户指南构建的十分良好,有 demo 有示例。我这里是对其内容了解的形式进行重构,在介绍概念方面个别是翻译 JavaFX 的文档,这些概念是必要的,也很简略直观。

JavaFX 是什么?

概述

JavaFX is a set of graphics and media packages that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.

我的翻译: JavaFX 是一组图形化和多媒体工具包,可让开发者设计、创立、测试、调试和部署跨平台的客户端应用程序。

chatGPT 的翻译是: JavaFX 是一套图形和媒体包,可让开发人员设计、创立、测试、调试和部署在各种平台上统一运行的丰盛客户端应用程序。

JavaFX 是一个用于开发跨平台图形化应用程序的工具包。

JavaFX Applications

Since the JavaFX library is written as a Java API, JavaFX application code can reference APIs from any Java library. For example, JavaFX applications can use Java API libraries to access native system capabilities and connect to server-based middleware applications.

JavaFX 库应用 Java 来编写,所以 JavaFX 中能够应用任何 Java 库的代码。例如 JavaFX 利用能够应用 Java 库和操作系统进行交互、连贯服务端应用程序。

The look and feel of JavaFX applications can be customized. Cascading Style Sheets (CSS) separate appearance and style from implementation so that developers can concentrate on coding. Graphic designers can easily customize the appearance and style of the application through the CSS.

JavaFX 的界面外观反对自定义,能够应用 CSS 将外观与款式拆散的实现能够让开发人员分心编码。设计师能够轻松的应用 CSS 定制应用程序的外观和款式。

If you have a web design background, or if you would like to separate the user interface (UI) and the back-end logic, then you can develop the presentation aspects of the UI in the FXML scripting language and use Java code for the application logic.

如果你有网页开发背景,或者你想将 UI 解决逻辑与用户界面显示进行拆散,那么你能够抉择用 FXML 脚本语言来构建页面,应用 Java 来构建 UI 管制逻辑。

If you prefer to design UIs without writing code, then use JavaFX Scene Builder. As you design the UI, Scene Builder creates FXML markup that can be ported to an Integrated Development Environment (IDE) so that developers can add the business logic.

如果你并不想应用写代码的形式来构建用户界面,那么这里能够应用 JavaFX Scene Builder,通过拖拽的模式设计好用户界面之后能够间接导出 FXML 给开发人员应用,开发人员只须要在 UI 界面前面增加解决逻辑即可实现客户端应用程序的构建。

在翻材料的过程中,在 B 站看到有 up 主吐槽这个 Scene Builder 难用,这里咱们到时候试一下,看看新版本的是否那么难用。

Availability 可用的

The JavaFX APIs are available as a fully integrated feature of the Java SE Runtime Environment (JRE) and the Java Development Kit (JDK).

JavaFX API 是作为 Java SE 运行时环境和 Java 开发工具包的一项齐全集成性能提供。

Because the JDK is available for all major desktop platforms (Windows, Mac OS X, and Linux), JavaFX applications compiled to JDK 7 and later also run on all the major desktop platforms.

因为 JDK 可能运行在所有支流的桌面平台 (Windows, Mac OS X, Linux),因而编译到 JDK7 版本以上包含 JDK 7 的 JavaFX 应用程序也能够在支流版本上运行。

Support for ARM platforms has also been made available with JavaFX 8. JDK for ARM includes the base, graphics and controls components of JavaFX.

JavaFX 8 还提供了对 ARM 平台的反对,JDK FOR ARM 包含 JavaFX 根底、图形和控件。

The cross-platform compatibility enables a consistent runtime experience for JavaFX applications developers and users.

跨平台兼容性让 JavaFX 开发人员和用户在运行时能够享受统一的体验。

Key Features

这里只介绍有用的:

  • FXML and Scene Builder. FXML is an XML-based declarative markup language for constructing a JavaFX application user interface. A designer can code in FXML or use JavaFX Scene Builder to interactively design the graphical user interface (GUI). Scene Builder generates FXML markup that can be ported to an IDE where a developer can add the business logic.

​ FXML 是一种基于 XML 申明性标记语言,用于构建 JavaFX 应用程序用于界面。开发者能够在 FXML 编写代码,或者应用 Scene Builder 去设计用户界面,设计实现之后导出到 FXML 文件,开发人员在界面前面增加逻辑即可实现应用程序的构建。

  • WebView. A web component that uses WebKitHTML technology to make it possible to embed web pages within a JavaFX application. JavaScript running in WebView can call Java APIs, and Java APIs can call JavaScript running in WebView. Support for additional HTML5 features, including Web Sockets, Web Workers, and Web Fonts, and printing capabilities have been added in JavaFX 8. See Adding HTML Content to JavaFX Applications。

​ 通过 WebKitHTML,JavaFX 利用能够应用 Web 组件和 Web 页面。运行在 WebView 中的 JavaScript 能够调用 Java APIS,Java APIs 也能够调用运行在 Web View 中的 JavaScript。除此之外,在 JavaFX 还能够应用 HTML 5 的个性,包含 Web Socket,Web Worker,Web 字体、打印性能。

​ 参看:Adding HTML Content to JavaFX Applications 这一章节:https://docs.oracle.com/javas…

  • Swing interoperability. Existing Swing applications can be updated with JavaFX features, such as rich graphics media playback and embedded Web content. The SwingNode class, which enables you to embed Swing content into JavaFX applications, has been added in JavaFX 8. See the SwingNode API javadoc and Embedding Swing Content in JavaFX Applications for more information.

​ 集成 Swing,Swing 利用能够应用 Java FX 的个性,比方丰盛的图形化、多媒体播放,嵌入 Web 的内容。在 JavaFX 8 中增加了 SwingNode 类,它可能让 Swing 内容嵌入到 JavaFX 应用程序中。

参看 SwingNode API javaDoc:https://docs.oracle.com/javas…

Embedding Swing Content in JavaFX Applications https://docs.oracle.com/javas…

  • Built-in UI controls and CSS. JavaFX provides all the major UI controls that are required to develop a full-featured application. Components can be skinned with standard Web technologies such as CSS. The DatePicker and TreeTableView UI controls are now available with the JavaFX 8 release. See Using JavaFX UI Controls for more information. Also, the CSS Styleable* classes have become public API, allowing objects to be styled by CSS.

​ UI 控件和 CSS: JavaFX 提供了支流的 UI 控件,开发者能够应用这些 UI 控件开发进去体验良好的利用。组件能够应用规范 WEB 技术来进行丑化,比方 CSS。

​ DatePicker 和 TreeTableView UI 控件在 JavaFX 被公布,你能够在 JavaFX 中应用它。参看 Using JavaFX UI Controls: https://docs.oracle.com/javas…。除此之外 CSS 在 JavaFX 8 也裸露给开发者应用,容许应用 CSS 设置款式。

  • Modena theme The Modena theme replaces the Caspian theme as the default for JavaFX 8 applications. The Caspian theme is still available for your use by adding the setUserAgentStylesheet(STYLESHEET_CASPIAN) line in your Application start() method. For more information, see the Modena blog at fxexperience.com

​ Modena 主题,在 JavaFX 中 modena 主题取代了 Caspian 主题成为默认主题。Caspian 主题依然是可用的,你能够使 setUserAgentStylesheet(STYLESHEET_CASPIAN) 在利用启动的时候应用 Caspian 主题。更多信息参看:http://fxexperience.com/2013/…

  • 3D Graphics Features. The new API classes for Shape3D (Box, Cylinder, MeshView, and Sphere subclasses), SubScene, Material, PickResult, LightBase (AmbientLight and PointLight subclasses), and SceneAntialiasing have been added to the 3D Graphics library in JavaFX 8. The Camera API class has also been updated in this release. For more information, see the Getting Started with JavaFX 3D Graphicsdocument and the corresponding API javadoc for javafx.scene.shape.Shape3D, javafx.scene.SubScene, javafx.scene.paint.Material, javafx.scene.input.PickResult, and javafx.scene.SceneAntialiasing.

​ 3D 图形化个性。新的 API 接口类为 Shape3D(Box,Cylinder,MeshView,Sphere 是子类)、SubScene、Material、PickResult、LightBase(AmbientLight 和 PointLight 是它的子类)。SceneAntialiasing(抗锯齿) 在 JavaFX 8 被引入 3D 图形库。Camera API 相干的类库在这次公布也被更新。更多的信息参看: Getting Started with JavaFX 3D Graphics:https://docs.oracle.com/javas… 和 javafx.scene.shape.Shape3D, javafx.scene.SubScene, javafx.scene.paint.Material, javafx.scene.input.PickResult, and javafx.scene.SceneAntialiasing. 的 API 文档。

  • Canvas API. The Canvas API enables drawing directly within an area of the JavaFX scene that consists of one graphical element (node).

​ Canvas API: 能够在由一个图形元素结点组成的 JavaFX 的场景区域内间接绘制图形、文本和其余内容。

  • Printing API. The javafx.print package has been added in Java SE 8 release and provides the public classes for the JavaFX Printing API。

​ javafx.print 被增加进入 Java SE 8,为 JavaFX 打印相干 API 提供了根底类。所以在 JavaFX 中咱们就能够管制打印设置,预览打印内容,并执行打印操作。具体的办法阐明请参看: https://docs.oracle.com/javas…

  • Rich Text Support. JavaFX 8 brings enhanced text support to JavaFX, including bi-directional text and complex text scripts, such as Thai and Hindu in controls, and multi-line, multi-style text in text nodes.

​ 富文本反对: JavaFX 8 进一步加强了对文本的反对。包含双向文本 和 简单文件脚本。

  • Multitouch Support. JavaFX provides support for multitouch operations, based on the capabilities of the underlying platform.

​ 多点触控反对。JavaFX 基于底层平台提供了多点触控的反对。

  • Hi-DPI support. JavaFX 8 now supports Hi-DPI displays.

​ JavaFX 当初反对高 DPI 显示。

  • Hardware-accelerated graphics pipeline. JavaFX graphics are based on the graphics rendering pipeline (Prism). JavaFX offers smooth graphics that render quickly through Prism when it is used with a supported graphics card or graphics processing unit (GPU). If a system does not feature one of the recommended GPUs supported by JavaFX, then Prism defaults to the software rendering stack.

​ 硬件加速图形管道。JavaFX 图形是基于图形渲染管道。如果当 JavaFX 所处的平台有 GPU 或者显卡,JavaFX 会让图形渲染更加晦涩。如果没有 JavaFX 反对的 GPU,那么会应用软件渲染机制。

  • High-performance media engine. The media pipeline supports the playback of web multimedia content. It provides a stable, low-latency media framework that is based on the GStreamer multimedia framework.

​ 高性能的多媒体引擎,多媒体管道反对播放多媒体内容,提供了一个基于 GSStream 的高稳固、低提早的多媒体框架。

  • Self-contained application deployment model. Self-contained application packages have all of the application resources and a private copy of the Java and JavaFX runtimes. They are distributed as native installable packages and provide the same installation and launch experience as native applications for that operating system.

​ 自蕴含的应用程序部署将所有程序须要的资源、Java 运行时、JavaFX 运行时打包。他们被散发为各个操作系统反对的安装包,而且在各个操作系统上都能取得统一的体验。

参考资料

  • Java Platform, Standard Edition (Java SE) 8 Client Technologies https://docs.oracle.com/javas…
  • 场景图 https://en.wikipedia.org/wiki…
正文完
 0