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

📄 slide.java

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

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

public class Slide extends Applet
    implements Runnable
{

    public synchronized void paint(Graphics g)
    {
        if(imageNo == 1)
        {
            g.drawImage(images[0], 0, 0, imageWidth, nowHeight, 0, imageHeight - nowHeight, imageWidth, imageHeight, null);
            g.drawImage(images[amount - 1], 0, nowHeight, imageWidth, imageHeight, 0, 0, imageWidth, imageHeight - nowHeight, null);
            return;
        }
        else
        {
            g.drawImage(images[imageNo - 1], 0, 0, imageWidth, nowHeight, 0, imageHeight - nowHeight, imageWidth, imageHeight, null);
            g.drawImage(images[imageNo - 2], 0, nowHeight, imageWidth, imageHeight, 0, 0, imageWidth, imageHeight - nowHeight, null);
            return;
        }
    }

    public Slide()
    {
        delay = 1000;
        speed = 15;
    }

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

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

    public void run()
    {
        do
        {
            nowHeight += step;
            if(nowHeight >= imageHeight - step)
            {
                nowHeight = imageHeight;
                repaint();
                try
                {
                    Thread.sleep(delay);
                }
                catch(Exception _ex) { }
                nowHeight = 0;
                if(imageNo >= amount)
                    imageNo = 1;
                else
                    imageNo++;
            }
            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;
        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]);

        if(getParameter("delay") != null)
            delay = Integer.parseInt(getParameter("delay"), 10);
        if(getParameter("speed") != null)
            speed = Integer.parseInt(getParameter("speed"), 10);
        speed = speed >= 10 ? speed : 10;
        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 = 0;
        step = imageHeight / 20;
        step = step != 0 ? step : 1;
        repaint();
    }

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

⌨️ 快捷键说明

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