⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imageupdater.java

📁 一个画图程序
💻 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 + -