?? imageupdater.java
字號:
import java.applet.*;
import java.awt.*;
import java.awt.image.ImageObserver;
public class ImageUpdater extends Applet
{
Image xiaofangshuan,a;
int smallx,smally,smallw,smallh;
boolean sizeknown=false;
boolean errored=false;
public static void main(String args[])
{
Frame frame=new Frame();
ImageUpdater ht=new ImageUpdater();
ht.init();
frame.add(ht);
frame.setSize(1000,600);
frame.show();
}
public void init()
{
xiaofangshuan=getImage(getCodeBase(),"xf1.GIF");
a=getImage(getCodeBase(),"xf2.GIF");
positionImages();
}
public boolean imageUpdate(Image theimg,int infoflags,int x,int y,int w,int h)
{
if((infoflags&(ERROR))!=0)
{
errored=true;
}
if((infoflags&(WIDTH|HEIGHT))!=0)
{
positionImages();
}
boolean done=((infoflags&(ERROR|FRAMEBITS|ALLBITS))!=0);
repaint(done?0:100);
return!done;
}
public synchronized void positionImages()
{
Dimension d=size();
int xfsw=xiaofangshuan.getWidth(this);
int xfsh=xiaofangshuan.getHeight(this);
smallw=a.getWidth(this);
smallh=a.getHeight(this);
if(xfsw<0||xfsh<0||smallw<0||smallh<0)
{
return;
}
smallw=smallw*d.width/xfsw;
smallh=smallh*d.height/xfsh;
smallx=(d.width-smallw)/2;
smally=(d.height-smallh)/2;
sizeknown=true;
}
public synchronized void paint(Graphics g)
{
Dimension d=size();
int appw=d.width;
int apph=d.height;
if(errored)
{
g.setColor(Color.red);
g.fillRect(0,0,appw,apph);
return;
}
g.drawImage(xiaofangshuan,0,0,appw,apph,this);
if(sizeknown)
{
g.drawImage(a,smallx,smally,smallw,smallh,this);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -