ScalaFX和Akka(查看留言Actor)

时间:2015-03-09 12:46:21

标签: akka scalafx

Mucaho's Scalatrix示例我想从View(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")
  }
}

1 个答案:

答案 0 :(得分: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
}