日期:2014-05-20 浏览次数:21062 次
//<applet code = "Ani.class" height = "200" width = "200">
//</applet>
import java.awt.*;
import javax.swing.*;
class ImagePanel extends JPanel
{
Image[] img;
int currentImage = 0;
public ImagePanel(Image[] img)
{
this.img = img;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(img[currentImage], 0, 25, this);
currentImage = (currentImage + 1) % 10;
}
public void run()
{
while (true)
{
repaint();
try
{
Thread.sleep(200);
} catch (InterruptedException e) { }
}
}
}
public class Ani extends JApplet
{
ImagePanel panel = null;
Image[] image = new Image[10];
Thread t = null;
public void init()
{
for (int i = 0; i < 10; i++)
{
image[i] = getImage(getDocumentBase(), "T"+(i+1)+".gif");
}
panel = new ImagePanel(image);
panel.setBackground(Color.GREEN);
getContentPane().add(panel);
}
public void start()
{
t = new Thread(panel);
t.start();
}
}