0

我正在使用scalas运行一个简单的 scala.swing 应用程序:

#!/usr/bin/env scalas

/***         
scalaVersion := "2.12.6"
libraryDependencies += "org.scala-lang.modules" %% "scala-swing" % "2.1.1"
*/         


import scala.swing._

object FirstSwingApp extends SimpleSwingApplication {
  def top = new MainFrame {
    title = "First Swing App"
    contents = new Button {
      text = "Click me"
    }
  }
}

这会编译并运行(在 OSX 10.14 上),但没有可见的输出;该过程仅在几秒钟后终止。我做错了什么?

4

1 回答 1

0

从这个文档https://www.scala-sbt.org/release/docs/Scripts.html来看-scalas不像java -jar ...,也就是说,它没有main在某些object.

它只是像 REPL 一样执行代码,所以如果你想执行代码,请自己运行它:

#!/usr/bin/env scalas

/***         
scalaVersion := "2.12.6"
libraryDependencies += "org.scala-lang.modules" %% "scala-swing" % "2.1.1"
*/         


import scala.swing._

// creates object but doesn't run anything
object FirstSwingApp extends SimpleSwingApplication {
  def top = new MainFrame {
    title = "First Swing App"
    contents = new Button {
      text = "Click me"
    }
  }
}

FirstSwingApp.main(new Array[String](0)) // run main manually, or whatever you prefer
于 2019-07-25T13:59:03.087 回答