Scala 和 Swing GUI 应用程序

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

Scala and Swing GUI applications

user-interfaceswingscala

提问by ZacharyP

From reading parts of the Programming in Scala book, I realize that Scala can work with the Java Swing components to create GUI applications.

通过阅读《Scala 编程》一书中的部分内容,我意识到 Scala 可以使用 Java Swing 组件来创建 GUI 应用程序。

My question is if there are any projects or released applications (that are more than just simple examples) that use Scala and Swing?

我的问题是是否有任何项目或已发布的应用程序(不仅仅是简单的示例)使用 Scala 和 Swing?

回答by oxbow_lakes

Is this because you wish to see some actual Scala Swing code, or are you just interested as to whether Scala Swing is "production-ready"? If it is the latter, Scala Swing is pretty good: I've started using it for all GUI code. Compare:

这是因为您希望看到一些实际的 Scala Swing 代码,还是您只是对 Scala Swing 是否“生产就绪”感兴趣?如果是后者,Scala Swing 相当不错:我已经开始将它用于所有 GUI 代码。比较:

JButton b = new JButton();
b.setText("OK");
b.setFont(f);
b.setPreferredSize(new Dimension(20, 20));
b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      //reacction here
    }
});

with:

和:

val b = new Button {
  text = "OK"
  font = f
  preferredSize = (20, 20)
}
listenTo(b)
reactions += {
  case ButtonClicked(`b`) => //reaction here
}

As Scala Swing is really just a lightweight layer on top of Java Swing, you can integrate any Java Swing component easily and be sure that it all works OK.

由于 Scala Swing 实际上只是 Java Swing 之上的一个轻量级层,因此您可以轻松集成任何 Java Swing 组件并确保它一切正常。

That said, the documentation as of Scala 2.7 is pretty poor. I understand that Scala Swing is being upgraded in the 2.8 release and that this will include improved documentation.

也就是说,Scala 2.7 的文档非常糟糕。我知道 Scala Swing 正在 2.8 版本中升级,这将包括改进的文档。

回答by HRJ

House of Mirrors

镜之屋

I have written this gamein Scala. It's open-source and uses Swing via both the Java and Scala library interfaces.

我已经用Scala编写了这个游戏。它是开源的,并通过 Java 和 Scala 库接口使用 Swing。

The Scala API is great to work with as oxbox_lakes illustrated. I had to use the Java interface only for specific low level control such as custom alpha composition.

正如 oxbox_lakes 所示,Scala API 非常适合使用。我不得不仅将 Java 接口用于特定的低级控制,例如自定义 alpha 组合。

Before the Scala-swing library had become stable, the game was based on Scala-Squib, but that project has paused AFAIK.

在 Scala-swing 库变得稳定之前,该游戏基于Scala-Squib,但该项目已暂停 AFAIK。

回答by Bostone

There is Scalideat Google code, and then Scala itself has Swinglibrary

Google 代码中有Scalade,然后 Scala 本身就有Swing

回答by Thimmayya

I attended a talk recently on Scala and one of the products demo-ed was a Scala-Swing Twitter client. It is open-source and the project is TalkingPuffin. The UI looked pretty slick for a Swing project and I believe the project is looking for contributors.

我最近参加了一个关于 Scala 的演讲,其中一个产品演示是 Scala-Swing Twitter 客户端。它是开源的,项目是TalkingPuffin。一个 Swing 项目的 UI 看起来非常漂亮,我相信该项目正在寻找贡献者。