Mat*_*etz 2 action scala scala-swing
我在关闭我的Scala摆动框架时遇到了问题.这是我的退出按钮的代码
val buttonExit = new Button {
text = "Exit"
action = Action("Exit") {
WorldActor.run(false)
closer
}
}
Run Code Online (Sandbox Code Playgroud)
close函数定义为:
def closer (){
top.close
}
Run Code Online (Sandbox Code Playgroud)
top是MainFrame.每次我试图关闭,它只是暂停并停止响应.
好像你可以打电话
dispose()
Run Code Online (Sandbox Code Playgroud)
在框架上.
dispose实现,scala.swing.Window因此适用于框架和对话框.
如果在最后一帧上调用,则调用dispose关闭(以可恢复的方式,使用pack和visible = true重新打开)其他帧并终止应用程序.
在任何quit()调用System.exit之前调用任何关闭代码的Frame调用上终止应用程序.
这是一个快速的黑客来说明
import swing._
object SwingThing extends SimpleSwingApplication {
def top = new MainFrame {frame =>
val sf = new Frame {secondFrame =>
title = "Secondary Frame"
visible = true
contents = new FlowPanel {
contents += new Button(Action("Close Me") {secondFrame.dispose()})
contents += new Button(Action("Exit") {quit()})
}
}
val recoverBtn = new Button(Action("Recover") {sf.pack(); sf.visible = true})
val closeBtn = new Button(Action("Close Me") {frame.dispose()})
val exitBtn = new Button(Action("Exit") {quit()})
contents = new FlowPanel {
contents += recoverBtn
contents += closeBtn
contents += exitBtn
}
}
}
Run Code Online (Sandbox Code Playgroud)