| //源程序清单 import java.awt.*; import java. applet.*; public class BackgroundImage extends Applet //继承Applet { Image picture; Boolean ImageLoaded=false; public void init() { picture=getImage(getCodeBase(),"Image.gif"); //装载图像 Image offScreenImage=createImage(size().width,size().height); //用方法createImage创建Image对象 Graphics offScreenGC=offScreenImage.getGraphics(); //获取Graphics对象 offScreenGC.drawImage(picture,0,0,this); //显示非屏幕图像 } public void paint(Graphics g) { if(ImageLoaded) { g.drawImage(picture,0,0,null); //显示图像,第四参数为null,不是this showStatus("Done"); } else showStatus("Loading image"); } public boolean imageUpdate(Image img,int infoflags,int x,int y,int w,int h) { if(infoflags= =ALLBITS) { imageLoaded=true; repaint(); return false; } else reture true; } } |
关注此文的读者还看过: