开发者

java - applet delete image

开发者 https://www.devze.com 2023-01-07 00:32 出处:网络
Sorry asking so many questions but believe me.. I tried Google first. :) When you use theg.drawIma开发者_如何学Cge in paint() on an Applet... is there a way you can remove it? What I mean is remove t

Sorry asking so many questions but believe me.. I tried Google first. :)

When you use the g.drawIma开发者_如何学Cge in paint() on an Applet... is there a way you can remove it? What I mean is remove the image that was drawn.


There's not really a direct way to clear the image, unless you are using an off screen buffer and painting that. I'm assuming you are drawing directly to the screen. To clear the image, you add a new flag to your applet, which you check in your paint() method. The flag indicates if the image should be drawn or not. E.g.

 boolean shouldDrawImage = true;

 void paint(Graphics g) {
    if (shouldDrawImage) {
        g.drawImage(...);
    }
 }

To clear the image, you then set the flag to false and invoke the repaint() method.


g.setColor( getBackground() );
g.fillRect(0, 0, getWidth(), getHeight());


public void removeImage(Image img, int id, width w, height h);

This function removes the image specified by name, id, height and width.

0

精彩评论

暂无评论...
验证码 换一张
取 消