开发者

Recursive value needs type - Scala Swing

开发者 https://www.devze.com 2023-03-26 05:50 出处:网络
I have a simple application with a panel, and I want to pause and restart painting when I click on it.

I have a simple application with a panel, and I want to pause and restart painting when I click on it.

object ModulusPatterns extends SimpleSwingApplication {
  var delay_ms = 200

  def top = new MainFrame {
    contents = panel
  }

  val panel = new Panel {
    override def paintComponent(g: Graphics2D) { /* draw stuff */ }
    listenTo(mouse.clicks)
    reactions += {
      case e: MouseClicked => {
        val r: Boolean = repainter.isRunning
        if (r) repainter.stop() else repainter.start()
      }
    }
  开发者_如何转开发}

  val repainter = new Timer(delay_ms, new ActionListener {
    def actionPerformed(e: ActionEvent) {
      panel.repaint
    }
  })

  repainter.start()
}

I get a compilation error on the val r definition line:

error: recursive value repainter needs type
val r: Boolean = repainter.isRunning

As far as I can tell I'm not doing anything recursive here. Is it a bug? Any workarounds?


As far as I can tell I'm not doing anything recursive here.

Yes, you are: the definition of panel refers to repainter, and the definition of repainter refers to panel. So there is no bug and you do need to specify types for them.

0

精彩评论

暂无评论...
验证码 换一张
取 消