Recursive value type required - Scala Swing

I have a simple application with a panel, and I want to pause and restart the 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 in 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 recursive here. This is mistake? Any workarounds?

+4
source share
1 answer

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

Yes, you: the definition of panel refers to repainter , and the definition of repainter refers to panel . Thus, there are no errors, and you need to specify types for them.

+7
source

All Articles