我在Scala中创建了一个GUI。它非常简单,但我想从DSLGUI外部修改DSLOutput对象。有谁知道如何从DSLGUI外部调用DSLOutput.append()?我曾尝试导入DSLGUI,但我似乎无法弄清楚如何访问DSLOutput。
package api
import swing._
import event._
object DSLGUI extends SimpleSwingApplication{
def top = new MainFrame{
title = "Computer Repair Advisory System"
object Commands extends TextField(columns = 50)
object DSLOutput extends TextArea(rows = 15, columns = 50)
object SendCommand extends Button("Send")
val CommandPanel = new FlowPanel{
contents += Commands
contents += SendCommand
}
contents = new BoxPanel(Orientation.Vertical){
contents +=CommandPanel
contents += DSLOutput
}
listenTo(SendCommand)
reactions += {
case ButtonClicked(SendCommand) =>
DSLOutput append "Test "
}
}
}
答案 0 :(得分:1)
您必须在DSLGUI
范围内声明它,而不是在top
方法中将其声明为本地对象。然后,您可以使用DSLGUI.DSLOutput
访问它。
即。
object DSLGUI extends SimpleSwingApplication {
object DSLOutput extends TextArea(rows = 15, columns = 50)
def top = new MainFrame {
...
}
}