Scala property bindings

联合创作 · 2023-10-01 01:29

This library provides property bindings similar to Qt signal slot system, JavaFx's properties and other.

示例程序:

private class Model {
  val text = new Observable("count: 0")
  private var count = 
  def increment() {
    count += 1
    text() = "count: " + count
  }
}

object Example extends SimpleSwingApplication {
  private val model = new Model

  def top = new MainFrame {
    title = "Example"
    contents = new GridPanel(2, 1) {
      val button = new Button("Press Me!")
      contents += button

      val label = new Label {
        text = observes(model.text, text_=)
      }
      contents += label

      listenTo(button)
      reactions += {
        case ButtonClicked(_) => model.increment()
      }
    }
  }
}
浏览 6
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报