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

📄 turnimage.java

📁 java applet编程,实现对相关图片声音的调用
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;

public class TurnImage extends Applet implements Runnable {
    int currentImage;
	int imageW, imageH;
    int delay = 3000;
	int allFrame = 4;
    Thread animatorThread;

	Image offImage = null;
	Graphics offGraphics = null;

	Image images[];
	MediaTracker tracker;

    public void init()
	{
		//setBackground(Color.black);

        String str;
  
        //How many milliseconds between frames?
        str = getParameter("fps");
        try {
            if (str != null)
			{
                delay = Integer.parseInt(str);
            }
        } catch (Exception e) {}

        //Load Images
        images = new Image[allFrame];
		tracker = new MediaTracker(this);

		for( int i = 1; i <= allFrame; i++ )
		{
			images[i-1] = getImage(getCodeBase(), "QQ" + i + ".gif");
			tracker.addImage(images[i-1], i-1);
		}
		try{
			tracker.waitForAll();
		}catch(Exception e){}

		imageW = images[0].getWidth(this);
		imageH = images[0].getHeight(this);

		currentImage = 0;
		offImage = images[0];
    }

    public void start()
	{
        //Start animating!
        if (animatorThread == null) {
            animatorThread = new Thread(this);
        }
        animatorThread.start();
    }

    public void stop()
	{
        //Stop the animating thread.
        animatorThread = null;
		offImage = null;
		offGraphics = null;
    }

    public void run()
	{
        //Just to be nice, lower this thread's priority
        //so it can't interfere with other processing going on.
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
 
        offImage = createImage(imageW, imageH);
		offGraphics = offImage.getGraphics();

		//This is the animation loop.
        while (Thread.currentThread() == animatorThread)
		{
            //Delay depending on how far we are behind.
            try {
                Thread.sleep(delay);

				//Display it.

				for( int i = 0; i <= imageW/2; i += 2 )  //宽度方向逐渐压缩
				{
					Thread.sleep(2);
					offGraphics.setColor(Color.white);
					offGraphics.fillRect(0, 0, imageW, imageH); 
					offGraphics.drawImage(images[currentImage], i, 0, imageW-2*i, imageH, this);
					repaint();
				}

				currentImage = (currentImage + 1) % allFrame;

				for( int i = 0; i <= imageW/2; i += 2 )  //宽度方向逐渐扩大
				{
					Thread.sleep(2);
					offGraphics.setColor(Color.white);
					offGraphics.fillRect(0, 0, imageW, imageH);
					offGraphics.drawImage(images[currentImage], imageW/2-i, 0, 2*i, imageH, this);
					repaint();
				}

            } catch (InterruptedException e) {
                break;
            }
        }
    }

    public void paint(Graphics g)
	{
		if( offImage != null )
		{
			g.drawImage(offImage, 0, 0, this);
		}
    }

    public void update(Graphics g)
	{
		paint(g);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -