Scala/Groovy/Clojure 中的 GUI

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3324519/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 02:18:38  来源:igfitidea点击:

GUI in Scala/Groovy/Clojure

scalauser-interfacegroovyclojure

提问by Alexander Gromnitsky

Last time I had to deal with Java was 2005 and I forgot almost everything about it since then.

上次我不得不处理 Java 是在 2005 年,从那时起我几乎忘记了它的一切。

Today I need to build a GUI app on the top of Java. I guess it is better to use one of Scala/Groovy/Clojure languages.

今天我需要在 Java 之上构建一个 GUI 应用程序。我想最好使用 Scala/Groovy/Clojure 语言之一。

The question is: which of them is better for desktop GUI programming? My program will transform and display a series of jpeg/png files + there will be ~10 dialogs (with tons of options in each with all possible widgets).

问题是:它们中的哪一个更适合桌面 GUI 编程?我的程序将转换并显示一系列 jpeg/png 文件 + 将有大约 10 个对话框(每个对话框中都有大量选项和所有可能的小部件)。

The main requirement is compactness: I hate to write a dozen lines of code only to draw a simple frame with a button. My background in GUI is (mostly) Tcl/Tk and GTK+.

主要要求是紧凑:我讨厌写十几行代码只是为了用一个按钮绘制一个简单的框架。我的 GUI 背景(主要是)Tcl/Tk 和 GTK+。

采纳答案by Daniel C. Sobral

Scala comes with fairly complete sample applications for basic GUI elements, which you can run by typing scala scala.swing.test.UIDemoat the command line. You can browse the source code for them here.

Scala 为基本 GUI 元素提供了相当完整的示例应用程序,您可以通过scala scala.swing.test.UIDemo在命令行中键入来运行这些示例应用程序。您可以在此处浏览它们的源代码。

You may also look at this documentto get an idea of the design principles behind Scala's Swing wrappers.

您还可以查看此文档以了解 Scala 的 Swing 包装器背后的设计原则。

回答by Rayne

DISCLAIMER: I'm a Clojure programmer. I'm obviously biased.

免责声明:我是一名 Clojure 程序员。我显然有偏见。

Of all of those languages, I think Clojure and Groovy are probably the most compact. Scala is a curly-bracket language like Java, so it tends to take up a bit more space. However, it's nowhere near as verbose as Java is, and I think Scala is pretty awesome. I know that Scala has a swing wrapper. I've never done GUI development in Scala, so I can't really say how it feels.

在所有这些语言中,我认为 Clojure 和 Groovy 可能是最紧凑的。Scala 是一种像 Java 一样的大括号语言,因此它往往会占用更多空间。然而,它远没有 Java 那样冗长,而且我认为 Scala 非常棒。我知道 Scala 有一个摆动包装器。我从来没有在 Scala 中做过 GUI 开发,所以我真的说不出它的感觉。

I've done some swing development in Clojure, and it doesn't really take much. Using swing direct from Clojure can be tedious until you write yourself some abstractions, but altogether, swing apps are smaller than the same thing in Java because Clojure code tends to be shorter and more concise than Java code.

我已经在 Clojure 中进行了一些摇摆开发,实际上并没有花太多时间。在您自己编写一些抽象之前,直接从 Clojure 使用 Swing 可能会很乏味,但总的来说,swing 应用程序比 Java 中的相同东西要小,因为 Clojure 代码往往比 Java 代码更短、更简洁。

Clojure also has some wrappers of sorts to make swing development more Clojury. One of which is clj-swing. I've seen some code written using it, and it's pretty cool, and definitely more concise than direct interop.

Clojure 也有一些包装器可以使 Swing 开发更加 Clojury。其中之一是clj-swing。我已经看到一些使用它编写的代码,它非常酷,而且绝对比直接互操作更简洁。

Now, I don't know Groovy. I really don't know much of anything about it, but I know it's more compact than Java, so I imagine GUI development would be fairly compact as well.

现在,我不知道 Groovy。我真的对它一无所知,但我知道它比 Java 更紧凑,所以我想 GUI 开发也会相当紧凑。

I think Clojure is a safe bet. With clj-swing, or even directly using the Java GUI toolkits directly is going to be really compact compared to Java, and the ability to build abstractions over non-compact stuff with macros is definitely a huge plus. Clojure has my vote.

我认为 Clojure 是一个安全的选择。与 Java 相比,使用 clj-swing,甚至直接使用 Java GUI 工具包将非常紧凑,并且使用宏在非紧凑的东西上构建抽象的能力绝对是一个巨大的优势。Clojure 有我的投票权。

回答by Ted Naleid

Groovy has the Griffonframework which uses convention over configuration for building GUI apps on the JVM. It's similar to grails/rails but for a rich GUI rather than a web app.

Groovy 有Griffon框架,它使用约定优于配置在 JVM 上构建 GUI 应用程序。它类似于 grails/rails,但用于丰富的 GUI 而不是 Web 应用程序。

回答by Blacktiger

Groovy has something called the swing builderfor making GUI programming easier. Here is a piece of sample code from the groovy website, it creates a frame with a button and counts the number of times you click it:

Groovy 有一个叫做Swing builder 的东西,可以让 GUI 编程更容易。这是来自 groovy 网站的一段示例代码,它创建一个带有按钮的框架并计算您单击它的次数:

int count = 0
new SwingBuilder().edt {
  frame(title:'Frame', size:[300,300], show: true) {
    borderLayout()
    textlabel = label(text:"Click the button!", constraints: BL.NORTH)
    button(text:'Click Me',
         actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."; println "clicked"},
         constraints:BL.SOUTH)
  }
}

回答by Alexey Romanov

I am currently developing an SWT application in Scala and quite like it. But I do expect Clojure would be even more compact.

我目前正在 Scala 中开发 SWT 应用程序并且非常喜欢它。但我确实希望 Clojure 会更加紧凑。

回答by mikera

I've been writing a GUI by using Clojure directly with Swing. It has worked very well indeed so far. I've also written some custom UI components in Java that have proved very easy to integrate with the Clojure part of the code base.

我一直在通过直接使用 Clojure 和 Swing 来编写 GUI。到目前为止,它确实运作良好。我还用 Java 编写了一些自定义 UI 组件,事实证明这些组件很容易与代码库的 Clojure 部分集成。

I also think that clj-swinglooks great - possibly easier than using Swing directly if you don't have prior Swing experience.

我还认为clj-swing看起来很棒 - 如果您没有 Swing 之前的经验,可能比直接使用 Swing 更容易。