德国开元华人社区 开元周游
标题:
哪位大虾能帮着看看程序???
[打印本页]
作者:
河边的鱼
时间:
22.7.2003 11:19
import java.awt.*;<br>import java.applet.*;<br><br><br>public class BackgroundImage extends Applet {<br> <br> Image picture;<br> boolean ImageLoaded=false;<br> public void init() {<br> <br> picture=getImage(getCodeBase(),"st1824.jpg");<br> Image offScreenImage=createImage(size().width,size().height);<br> Graphics offScreenGC=offScreenImage.getGraphics();<br> offScreenGC.drawImage(picture,0,0,this);<br> }<br><br> public void paint(Graphics g) {<br> <br> if(ImageLoaded){<br> g.drawImage(picture,0,0,null);<br> showStatus("Done");<br> }<br> else<br> showStatus("Loading image");<br> <br> }<br> public boolean imageUpdate(Image img,int infoflags,int x,int y,int w,int h){<br> <br> if(infoflags==ALLBITS){<br> <br> ImageLoaded=true;<br> repaint();<br> return false;<br> }<br> <br> else<br> return true;<br> }<br>}<br><br><br><br><br><br><HTML><br><HEAD><br></HEAD><br><BODY><br><CENTER><br><APPLET<br> code = "BackgroundImage.class"<br> width = "1024"<br> height = "768"<br> ><br></APPLET><br></CENTER><br></BODY><br></HTML><br><br><br>这是我从书上抄下来的使用双缓冲技术显示图象的程序,可是我在编译后,第一次运行没有问题,再次点击刷新就不显示图象了,哪位大虾能帮忙改一下程序?<br><br><br><br>
作者:
天道酬勤,人道酬
时间:
22.7.2003 13:54
You should make a check to the Image whether is has been loaded or not. When you clikc the reload, it will not load the image again, because it has been loaded all.<br><br>The code is as follows, hope it will help you<br><br>import java.awt.*;<br>import java.applet.*;<br>import java.awt.image.ImageObserver;<br><br><br>public class Myown extends Applet implements ImageObserver<br>{<br><br> Image picture;<br> boolean ImageLoaded=false;<br> public void init()<br> {<br><br><b> picture=getImage(getCodeBase(),"summer.jpg");</b> if(picture != null)<br> {<br> Image offScreenImage = createImage(getSize().width, getSize().height);<br> Graphics offScreenGC = offScreenImage.getGraphics();<br> offScreenGC.drawImage(picture, 0, 0, this);<br> offScreenGC.finalize();<br><b> if(checkImage(offScreenImage,this)==ALLBITS)<br> {<br> ImageLoaded = true;<br> }<br> else<br> ImageLoaded = false;</b> }<br> else<br> System.out.println("NULL source");<br> }<br><br> public void paint(Graphics g)<br> {<br><br> if(ImageLoaded)<br> {<br> g.drawImage(picture,0,0,this);<br> showStatus("Done");<br> }<br> else<br> showStatus("Loading image");<br><br> g.dispose();<br> }<br> public boolean imageUpdate(Image img,int infoflags,int x,int y,int w,int h)<br> {<br> if(infoflags==ALLBITS)<br> {<br><br> ImageLoaded=true;<br> repaint();<br> return false;<br> }<br><br> else<br> return true;<br> }<br>}<br><br><br>
作者:
天道酬勤,人道酬
时间:
22.7.2003 14:00
It is not necessary to implement the ImageOberver interface, I just made it for test<br><br>Viel Spaß!
作者:
河边的鱼
时间:
22.7.2003 22:57
谢谢,我去测试一下。
欢迎光临 德国开元华人社区 开元周游 (https://bbs.kaiyuan.cn/)
Powered by Discuz! X3.2