import java.awt.*; import java.applet.*; import javax.imageio.*; public class MyApplet extends Applet implements Runnable { int index = 0; Image [] imgs = new Image[4]; public void init() { for(int i = 0;i<4;i++) { imgs [i] = ImageIO.read(new File("imgs\\t"+i+"gif")); } new Thread(this).start(); }
public void paint(Graphics g) { g.drawImage(imgs[index],200,200,this); g.setColor(Color.RED); g.draw3DRect(100,60,100,100,true); g.setColor(Color.blue); g.setFont(new Font(null,Font.ITALIC|Font.BOLD,26)); g.drawString(""+index, 0, 60 ); }
/** * Method run * * */ public void run() { while(true) { try { Thread.sleep(100); } catch(Exception e) { e.printStackTrace(); } index = (index+1)%4; repaint(); } }; } 我是把要显示的四张图片(分别是:t1.gif ,t2.gif ,t3.gif ,t4.gif)存放在imgs文件夹中,imgs文件夹我放在MyApplet工程的classes文件夹中。 请前辈们指教。。。。。。