[英]Recursive value needs type - Scala Swing
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: 我在val r
定义行上遇到了编译错误:
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
. 是的,你是: panel
的定义是指repainter
, repainter
定义器的定义是指panel
。 So there is no bug and you do need to specify types for them. 所以没有错误,你需要为它们指定类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.