问题描述
我是JavaFX的新手,我在JavaFX中遇到了2-3种设计UI的方法。
I am new to JavaFX and I come across 2-3 ways of designing UI in JavaFX.
- 简单的Java文件是一样的我们在Swing中使用的方法
- 我不知道的JavaFX脚本
- 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 !
-
如果您更熟悉java中的编码UI,则可以使用此方法。但是,我个人不喜欢这种方法,因为当你的应用程序过于复杂时,它会使代码变得复杂。
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的一节中,
From a section in Oracle docs, Why Use FXML
FXML可以是使用轻松设计,这是一个 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编程方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!