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) { } 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?
source share