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.
加载中,请稍侯......
精彩评论