日期:2014-05-20 浏览次数:21013 次
public Image[]img;
public int index ;
public MyCanvas() {
try {
img= new Image[3];
img[0] = Image.createImage("/1.PNG") ;
img[1] = Image.createImage("/2.PNG") ;
img[2] = Image.createImage("/3.PNG") ;
new Thread(this).start() ;
} catch (IOException e) {
e.printStackTrace();
}
}
public void paint(Graphics g) {
g.setColor(0);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(img[index], 0, 0, 0);
}
public void run() {
while (true) {
repaint();
serviceRepaints();
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
index =(index == 2) ? index = 0 : ++index;
}
}