Java vs JavaFX Script vs FXML.在 JavaFX 中哪种编程方式更好? [英] Java vs JavaFX Script vs FXML. Which is better way of programming in JavaFX?

查看:36
本文介绍了Java vs JavaFX Script vs FXML.在 JavaFX 中哪种编程方式更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 JavaFX 的新手,我遇到了 2-3 种在 JavaFX 中设计 UI 的方法.

  1. 简单的 Java 文件,与我们在 Swing 中使用的方法相同
  2. 我不知道的 JavaFX 脚本
  3. FXML 是用于 UI 设计的基于 xml 的文件

哪个更好?为什么?

解决方案

简单说一下,javafx 脚本在 javafx 2.0 之前使用,不再使用!

  1. 如果您更熟悉 java 中的编码 UI,则可以使用此方法.但是,我个人不喜欢这种方法,因为当您的应用程序过于复杂时,它会使代码变得复杂.

  2. JavaFX Script 在 JavaFX 2.0 之前就在使用,不再使用

  3. 基于 FXML 的 UI 设计是在 Javafx 2.0 中引入的.这些帮助程序员使用 MVC 方法编写 javafx 应用程序.可以找到对 FXML 的非常好的介绍 这里.

    来自 Oracle 文档中的一个部分,为什么使用 FXML

<块引用>

从模型视图控制器 (MVC) 的角度来看,包含用户界面描述的 FXML 文件就是视图.控制器是一个 Java 类,可选择实现 Initializable 类,该类被声明为 FXML 文件的控制器.该模型由在 Java 端定义的域对象组成,您可以通过控制器连接到视图.

可以使用 Scene Builder,这是一个用于 javafx 应用程序的 Drag n Drop UI 设计器.使用 FXML 有以下优点:

  • 您的应用程序遵循 MVC 结构,就像企业 JavaEE 应用程序一样.
  • 表示层(UI)与应用层(逻辑)分离,这使得在需要时可以轻松更改应用程序的外观,就像网站一样!莉>
  • FXML 为您的应用程序带来了可扩展性和可维护性.

我对您的建议是使用 FXML.如果您不了解它们,请学习它们.这将是值得的!

I am new to JavaFX and I come across 2-3 ways of designing UI in JavaFX.

  1. Simple Java file which is same methodology we used in Swing
  2. JavaFX Script which I don't know
  3. FXML which is xml based file for UI designing

Which of these is better? and why?

解决方案

Just to put some light, javafx script was used prior to javafx 2.0 and is no longer in use !

  1. You can use this approach, if you are more familiar with the coding UI in java. But, I personally dislike the approach, since it makes the code complex when you have a way too complex application.

  2. JavaFX Script was in use prior to JavaFX 2.0 and is no longer in use

  3. FXML based UI design was introduced in Javafx 2.0. These help a programmer to code a javafx application, using a MVC approach. A very good introduction to FXML can be found here.

    From a section in Oracle docs, Why Use FXML

From a Model View Controller (MVC) perspective, the FXML file that contains the description of the user interface is the view. The controller is a Java class, optionally implementing the Initializable class, which is declared as the controller for the FXML file. The model consists of domain objects, defined on the Java side, that you connect to the view through the controller.

The FXML can be easily designed using Scene Builder, which is a Drag n Drop UI designer for javafx application. Using FXML has the following advantages :

  • Your application follows a MVC structure, just like enterprise JavaEE applications.
  • The Presentation Layer(UI) is segregated from the Application layer(logic), which makes it easy to change the look and feel of the application as and when required, just like websites !
  • FXML's brings in scalability and maintainability in your applications.

My suggestion for you would be to go with the FXML's. If you are not aware of them, learn them. It will be worth it!

这篇关于Java vs JavaFX Script vs FXML.在 JavaFX 中哪种编程方式更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆