如果我运行这个示例代码
class ExampleGUIElement extends Panel
{
preferredSize = new Dimension(100, 100)
val rand : Random = Random
override def paintComponent(g: Graphics2D) = g.drawLine(rand.nextInt(10),rand.nextInt(10),rand.nextInt(90) + 10 ,rand.nextInt(90) + 10)
}
object GUITest extends SimpleSwingApplication
{
def top = new MainFrame
{
contents = new ExampleGUIElement
}
}
它显然只显示了最初绘制的一条线。如果我想要定期重绘,我通常只会在最外面的 JFrame 上创建一个调用重绘的 Timer。但是 SimpleSwingApplication 没有这个方法,至少我找不到它,而调用 top.repaint 什么也没做。那么你如何定期重新粉刷整个东西呢?