我正在研究简单的计数器。我的问题是 drawString() 方法在旧字符串上绘制新字符串。以前怎么清除旧的?代码...
package foobar;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class board extends JPanel implements Runnable {
Thread animator;
int count;
public board() {
this.setBackground( Color.WHITE );
count = 0;
animator = new Thread( this );
animator.start();
}
@Override
public void run() {
while( true ) {
++count;
repaint();
try {
animator.sleep( 1000 );
} catch ( InterruptedException e ) {}
}
}
@Override
public void paint( Graphics Graphics ) {
Graphics.drawString( Integer.toString( count ), 10, 10 );
}
}
PS我是Java新手,所以请不要害怕告诉我我应该在我的代码中修复哪些其他内容......