Java vs JavaFX Script vs FXML. Which is better way of programming in JavaFX?

拥有回忆 提交于 2020-01-09 07:47:08

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/22828037/java-vs-javafx-script-vs-fxml-which-is-better-way-of-programming-in-javafx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!