思路:每过一秒,画圆的60之1!!!也就是一分钟正好画完一个圆,出现了不显示的问题,大家帮忙看看!
代码如下!
import java.awt.*;
public class TimeCircle {
public static void main(String args[]) {
new PaintFrame().launchFrame();
}
}
class PaintFrame extends Frame {
static int i = 1;
public void launchFrame() {
setBounds(200, 200, 640, 460);
setVisible(true);
}
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.red);
//g.fillOval(50, 50, 30, 30);
System.out.print(i);
try {
Thread.sleep(1000);
this.repaint();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
g.drawArc(100, 100, 300, 300, 0, i*6);
i ++;
//g.setColor(Color.green);
//g.fillRect(80, 80, 40, 40);
g.setColor(c);
}
}
/*
class MyThread implements Runnable {
@Override
public void run() {
while(true){
try {
Thread.sleep(1000);
new PaintFrame().launchFrame();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
*/
------解决方案--------------------
g.drawArc(100, 100, 300, 300, 0, i*6);
因为随着i的递增,i*6没有规律。