请问,请问java repaint 重复的问题,遇到了一个麻烦,就是用重复drafting 来表达Pacman Open&Close 的嘴巴动作。但是这个程序只有一次不会动......有人可以帮我解决这个问题......非常感谢!:D
我的代码如下:
package Strive;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
class CDrawF extends JFrame {
CDrawF (){
setTitle("繪製各式圖形"); //JFrame interface
setBounds(50, 50, 490, 260); setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
for(int i = 0; i<= 360; i++){ //repeatly 360 times
repaint();
g2.setColor(new Color(1.0f, 0.0f, 1.0f));
g2.fill(new Arc2D.Double(100, 100, 80, 80, 30, 300, Arc2D.PIE));
//PacMan close mouth
repaint();
try{ //Delay setions
Thread.sleep(1000);
}catch(InterruptedException ex){}
g2.fill(new Arc2D.Double(100, 100, 80, 80, 10, 340, Arc2D.PIE));
//PacMan open mouth
repaint();
}
}
}
public class NewClass { //Main
public static void main(String[] args){
new CDrawF ();
}
}