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

📄 overturn.java

📁 JSP核心技术源代码,和本站的JSP核心技术分析,可以合用
💻 JAVA
字号:
// Compiled by PostGoods.com .
// Author: Haowen Huang 
// Example of Chapter 17 
// Source File Name:   OverTurn.java

import java.applet.Applet;
import java.awt.*;

public class OverTurn extends Applet
    implements Runnable
{

    public void paint(Graphics g)
    {
        int i = (imageHeight - nowHeight) / 2;
        g.drawImage(images[imageNo - 1], 0, i, imageWidth, nowHeight, null);
    }

    public OverTurn()
    {
        delay = 1000;
        speed = 30;
        color = Color.white;
    }

    public void update(Graphics g)
    {
        Graphics g1 = offScreenImage.getGraphics();
        g1.setColor(color);
        g1.fillRect(0, 0, imageWidth, imageHeight);
        paint(g1);
        g.drawImage(offScreenImage, 0, 0, null);
    }

    public void start()
    {
        thisThread = new Thread(this);
        thisThread.start();
    }

    public void run()
    {
        do
        {
            if(!order)
            {
                nowHeight -= step;
                if(nowHeight < step)
                {
                    order = true;
                    imageNo++;
                    imageNo = imageNo <= amount ? imageNo : 1;
                }
                repaint();
            }
            else
            {
                nowHeight += step;
                if(nowHeight > imageHeight - step)
                {
                    nowHeight = imageHeight;
                    order = false;
                    repaint();
                    try
                    {
                        Thread.sleep(delay);
                    }
                    catch(Exception _ex) { }
                }
                else
                {
                    repaint();
                }
            }
            try
            {
                Thread.sleep(speed);
            }
            catch(Exception _ex) { }
        }
        while(true);
    }

    public void init()
    {
        myTracker = new MediaTracker(this);
        images = new Image[10];
        imageNames = new String[10];
        imageNo = 1;
        amount = 0;
        order = false;
        if(getParameter("delay") != null)
            delay = Integer.parseInt(getParameter("delay"), 10);
        if(getParameter("speed") != null)
            speed = Integer.parseInt(getParameter("speed"), 10);
        if(getParameter("color") != null)
            color = stringToColor(getParameter("color"));
        speed = speed >= 10 ? speed : 10;
        int i = 1;
        do
        {
            imageNames[i - 1] = getParameter("pic" + i);
            if(imageNames[i - 1] == null)
                break;
            amount++;
        }
        while(++i < 11);
        for(int j = 0; j < amount; j++)
            images[j] = getImage(getDocumentBase(), imageNames[j]);

        for(int k = 0; k < amount; k++)
            myTracker.addImage(images[k], k);

        try
        {
            myTracker.waitForAll();
        }
        catch(Exception _ex) { }
        imageHeight = images[0].getHeight(this);
        imageWidth = images[0].getWidth(this);
        offScreenImage = createImage(imageWidth, imageHeight);
        nowHeight = imageHeight;
        step = imageHeight / 10;
        step = step != 0 ? step : 2;
        setBackground(Color.white);
    }

    private Color stringToColor(String s)
    {
        int i = Integer.decode("0x" + s.substring(0, 2)).intValue();
        int j = Integer.decode("0x" + s.substring(2, 4)).intValue();
        int k = Integer.decode("0x" + s.substring(4, 6)).intValue();
        return new Color(i, j, k);
    }

    private MediaTracker myTracker;
    private int imageHeight;
    private int imageWidth;
    private int nowHeight;
    private int imageNo;
    private int amount;
    private int step;
    private int delay;
    private int speed;
    private boolean order;
    private Image images[];
    private String imageNames[];
    private Image offScreenImage;
    private Color color;
    private Thread thisThread;
}

⌨️ 快捷键说明

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