例如下面的代碼顯示了一個簡單的表格如何從外部類以編程方式更新Scala/Swing?
import java.awt.Dimension
import swing._
object SunsetTable extends SimpleSwingApplication {
var model = Array(List("BHP", 1).toArray)
lazy val ui = new BoxPanel(Orientation.Vertical) {
val table = new Table(model, Array("Security", "Price")) {
preferredViewportSize = new Dimension(1200, 600)
}
contents += new ScrollPane(table)
}
def top = new MainFrame {
contents = ui
}
}
假設我有一個外部類
class Counter {
for (i <- 1 to 10) {
// update SunsetTable with i
Thread.sleep(1000)
}
}
我將如何更新與計數器i SunsetTable「價格」列?