Java 桌面应用程序框架与 JavaFX
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35019757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java desktop application frameworks vs. JavaFX
提问by Sonicsmooth
There are a lot of Java "application frameworks" such as those listed in http://pivot.apache.org/demos/which pretty much all use Swing as the GUI toolkit, or in the case of Eclipse, SWT.
有很多 Java“应用程序框架”,例如http://pivot.apache.org/demos/中列出的那些,它们几乎都使用 Swing 作为 GUI 工具包,或者在 Eclipse 的情况下,SWT。
However I have not seen any obvious frameworks for JavaFX. Why is this?
但是我还没有看到任何明显的 JavaFX 框架。为什么是这样?
If looking at the "Hollywood Principle", where the framework calls you, I would think JavaFX already does this, but then I'm confused because it would seem Swing and JavaFX do mostly the same role, which is as the GUI layer. But they both do event loops and callbacks/events/observer patterns, etc.
如果查看框架调用您的“好莱坞原理”,我会认为 JavaFX 已经做到了这一点,但随后我感到困惑,因为 Swing 和 JavaFX 似乎几乎扮演了相同的角色,即 GUI 层。但他们都做事件循环和回调/事件/观察者模式等。
Does merely implementing an event loop and calling your event handler not qualify as an "application framework"?
仅仅实现一个事件循环并调用您的事件处理程序是否不符合“应用程序框架”的要求?
If not, are there any frameworks based on JavaFX directly (rather than embedding JavaFX in a Swing control)? What would such a framework provide that JavaFX standalone does not?
如果没有,是否有任何直接基于 JavaFX 的框架(而不是将 JavaFX 嵌入到 Swing 控件中)?这样一个框架会提供什么,而 JavaFX 独立版没有?
Sorry for the "obviousness" of this question, but it's not obvious to me.
很抱歉这个问题的“显而易见性”,但对我来说并不明显。
thanks.
谢谢。
采纳答案by tomsontom
There are plenty of them looks like your research has not been very thorough
有很多看起来你的研究不是很彻底
- http://efxclipse.org/- in fact it leverages the same core stuff than the Eclipse 4 IDE / RCP 4 but replaces the SWT layer with JavaFX
- http://www.jrebirth.org/
- http://www.drombler.org/drombler-fx/
- http://jacpfx.org/
- http://efxclipse.org/- 事实上,它利用与 Eclipse 4 IDE / RCP 4 相同的核心内容,但用 JavaFX 替换了 SWT 层
- http://www.jrebirth.org/
- http://www.dromler.org/dromler-fx/
- http://jacpfx.org/
As I'm the author of e(fx)clipse I'm biased but I know first hand that it is used on (big) commercial projects
因为我是 e(fx)clipse 的作者,所以我有偏见,但我第一手知道它用于(大型)商业项目
回答by Ray
The simple answer to this is: JavaFX is much younger than Swing - at least as a standard JDK library. As a matter of fact, it only became a "real" standard part with Java 8. If you check the history, you see the following facts:
对此的简单回答是:JavaFX 比 Swing 年轻得多——至少作为标准的 JDK 库是这样。事实上,它只是在 Java 8 中才成为“真正”的标准部分。 如果您查看历史记录,您会看到以下事实:
- Before JavaFX 2 (released 2011), developers needed to learn a scripting language.
- Also before JavaFX 2, the implementation aimed at being platform independent and therefore made no use of system-specific resources which can make a big difference in graphics and animation.
- 在 JavaFX 2(2011 年发布)之前,开发人员需要学习一种脚本语言。
- 同样在 JavaFX 2 之前,该实现旨在独立于平台,因此没有使用特定于系统的资源,这些资源可以在图形和动画方面产生很大的不同。
Read through it, and you'll find some more interesting details which can be summed up in that probably most developers have only been "seriously" noticing JavaFX within the last 5 years or so. Swing goes back much further (especially as being baked into the standard Java Runtime Environment), so naturally there are far more libraries aimed at Swing than at FX.
通读它,您会发现一些更有趣的细节,总结起来可能是大多数开发人员在过去 5 年左右才“认真”地注意到 JavaFX。Swing 可以追溯到更远的地方(尤其是在融入标准 Java 运行时环境时),因此自然有更多的库是针对 Swing 的,而不是针对 FX 的。
回答by Sébastien B.
In my opinion, Swing, JavaFX and also SWT are graphical toolkit, providing a set of basic widgets. There are not "Application" frameworks because their main goal is to display an User Interface. But you can use them to build an application without any other library by using basic features.
在我看来,Swing、JavaFX 和 SWT 都是图形工具包,提供了一组基本的小部件。没有“应用程序”框架,因为它们的主要目标是显示用户界面。但是您可以使用它们通过使用基本功能来构建没有任何其他库的应用程序。
A good sample application can be found here: https://github.com/angelicalleite/museuid
一个很好的示例应用程序可以在这里找到:https: //github.com/angelicalleite/museuid
It looks really nice with data picked from a mysql database, but if you read carefully the source code you can notice that all SQL queries are performed within the UI thread which will slow down the UI responsiveness.
从 mysql 数据库中提取数据看起来非常好,但是如果您仔细阅读源代码,您会注意到所有 SQL 查询都在 UI 线程中执行,这会降低 UI 响应速度。
This is one of the reason you should use an Application Framework. Their goals vary and are numerous but they all are dedicated to ease your application development by keeping complex things (like multithreading, messaging) out of your application code.
这是您应该使用应用程序框架的原因之一。它们的目标各不相同,而且数量众多,但它们都致力于通过将复杂的事物(如多线程、消息传递)排除在应用程序代码之外来简化应用程序开发。
Your choice shall be done according to your personal convictions about architecture and dependencies you want to use (or don't).
您的选择应根据您对要使用(或不使用)的架构和依赖项的个人信念来完成。
I'm the author of JRebirth (disclaimer), but I sometimes have a look on other frameworks, so you can make your choice by asking yourself some basic questions:
我是 JRebirth(免责声明)的作者,但我有时会查看其他框架,因此您可以通过问自己一些基本问题来做出选择:
Do you want/need OSGI support ?
你想要/需要 OSGI 支持吗?
=> Yes efxclipse, DromblerFX, DEMUX
=> 是的 efxclipse、DromblerFX、DEMUX
=> No JRebirth,JacpFX, DataFX, griffonFX, afterburner.fx
=> 没有 JRebirth、JacpFX、DataFX、griffonFX、afterburner.fx
Do you want a minimalist framework?
你想要一个极简主义的框架吗?
=> Yes afterburner.fx
=> 是 afterburner.fx
Do you want/need event messaging?
你想要/需要事件消息吗?
Do you want to share code?
你想分享代码吗?
Do you want modularization?
你想要模块化吗?
Do you require Java 7 support ?
您需要 Java 7 支持吗?
How do you want to manage your application threads.
您希望如何管理您的应用程序线程。
I certainly forget a lot of questions.
我当然忘记了很多问题。
In fact you SHOULD use one of these Application Framework (building your own will be time-consuming), it will defintely speed up your developments and secure them, the remaining questions are :
事实上,您应该使用这些应用程序框架之一(构建您自己的应用程序框架将非常耗时),它肯定会加快您的开发速度并确保它们的安全,剩下的问题是:
- What AF will fit your needs ?
- What AF will be convenient to use for you and your team ?
- 什么 AF 将满足您的需求?
- 您和您的团队使用什么 AF 会很方便?
Choosing an AF using patterns you don't like could be painful, in any case you can contribute to any available AF because they are all open sourced.
使用您不喜欢的模式选择 AF 可能会很痛苦,在任何情况下,您都可以为任何可用的 AF 做出贡献,因为它们都是开源的。
Hope it helps,
希望能帮助到你,