4
我有一個簡單的應用程序面板,我想暫停並重新開始繪畫,當我點擊它。遞歸值需要類型 - Scala Swing
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()
}
我上val r
定義行編譯錯誤:
error: recursive value repainter needs type
val r: Boolean = repainter.isRunning
至於我可以告訴我什麼都沒做遞歸這裏。這是一個錯誤嗎?任何解決方法?
看來我只需要指定'panel'或'repainter'之一的類型。編譯器告訴我問題出現在'val r = ...'行中,讓我困惑了一下。我很驚訝它不能在這裏推斷類型。 –