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

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

问题描述

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

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


  1. 简单的Java文件是一样的我们在Swing中使用的方法

  2. 我不知道的JavaFX脚本

  3. FXML是基于xml的UI设计文件

哪个更好?为什么?

推荐答案

为了说明一点,javafx脚本在javafx 2.0之前使用并且不再使用了! / p>

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


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

  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.

JavaFX Script在JavaFX 2.0之前使用并且不再使用

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

在Javafx 2.0中引入了基于FXML的UI设计。这些帮助程序员使用MVC方法对javafx应用程序进行编码。 可以找到一个非常好的FXML介绍这里

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.

从Oracle docs的一节中,为什么使用FXML

From a section in Oracle docs, Why Use FXML




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

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.

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

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 :


  • 您的应用程序遵循MVC结构,像企业 JavaEE 应用程序。

  • 表示层(UI)与应用层(逻辑)隔离,这使得它很容易在需要时更改应用程序的外观,就像网站一样!

  • FXML带来应用程序中的可伸缩性和可维护性

  • 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.

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

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

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