0

Mucaho 的 Scalatrix示例中,我想从视图(ScalaFX)向controller演员发送消息,我如何抽象/公开演员才能做到这一点?

object Ops extends App {

  override def main(args: Array[String]): Unit = {
    new JFXPanel(); // trick: create empty panel to initialize toolkit
    new Thread(new Runnable() {
      override def run(): Unit = {
        View.main(Array[String]())
      }
    }).start()

    val system = ActorSystem("Ops")
    val controller = system.actorOf(Props[Controller], "controller")
  }
}

4

1 回答 1

0

目前我唯一想到的是将系统和参与者包装为另一个对象的可公开访问的成员

object Ops extends App {

  override def main(args: Array[String]): Unit = {
    new JFXPanel(); // trick: create empty panel to initialize toolkit
    new Thread(new Runnable() {
      override def run(): Unit = {
        View.main(Array[String]())
      }
    }).start()

    object Actors {
      val system = ActorSystem("Ops")
      val controller = system.actorOf(Props[Controller], "controller")
    }
  }
}

现在您可以在代码的任何部分发送消息,例如

object View extends JFXApp {
  stage = ...

  Ops.Actors.controller ! Tick
}
于 2015-03-13T09:51:36.053 回答