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

📄 lake.java

📁 只是倾向于JAVA3D的程序
💻 JAVA
字号:
// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2009-3-21 10:07:58
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Lake.java

import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;

public class Lake extends Applet
    implements Runnable
{

    public Lake()
    {
        boatPhaseTotal = 50;
        isAnimating = true;
        imgReflectName = "";
        imgOverlayName = "";
        target = "_self";
        isRocking = false;
    }

    public String getAppletInfo()
    {
        return "Name: Lake\r\nAuthor: David Griffiths\r\nCreated with Sun JDK 1.1";
    }

    public String[][] getParameterInfo()
    {
        String as[][] = {
            {
                "IMAGE", "String", "JPG or GIF file to reflect"
            }, {
                "OVERLAY", "String", "JPG or GIF file to use as overlay"
            }, {
                "HREF", "URL", "URL to link to"
            }, {
                "TARGET", "String", "Target frame"
            }, {
                "ROCK", "String", "ON for boat to rock"
            }
        };
        return as;
    }

    public void init()
    {
        String s = getParameter("IMAGE");
        if(s != null)
            imgReflectName = s;
        s = getParameter("OVERLAY");
        if(s != null)
            imgOverlayName = s;
        s = getParameter("HREF");
        if(s != null)
            try
            {
                m_HRef = new URL(getDocumentBase(), s);
            }
            catch(MalformedURLException _ex)
            {
                getAppletContext().showStatus("Bad URL: " + s);
                return;
            }
        s = getParameter("TARGET");
        if(s != null)
            target = s;
        s = getParameter("ROCK");
        if(s != null)
            isRocking = s.toUpperCase().equals("ON");
    }

    public void start()
    {
        if(m_Lake == null)
        {
            m_Lake = new Thread(this);
            m_Lake.start();
        }
    }

    public void stop()
    {
        if(m_Lake != null)
        {
            m_Lake.stop();
            m_Lake = null;
        }
    }

    public void run()
    {
        currImage = 0;
        if(!allLoaded)
        {
            repaint();
            gMain = getGraphics();
            imgReflect = loadImage(imgReflectName);
            if(!"".equals(imgOverlayName))
                imgOverlay = loadImage(imgOverlayName);
            if(!allLoaded)
            {
                stop();
                gMain.drawString("Error loading images!", 10, 40);
                return;
            }
            imgWidth = imgReflect.getWidth(this);
            imgHeight = imgReflect.getHeight(this);
            if(!"".equals(imgOverlayName))
            {
                overlayWidth = imgOverlay.getWidth(this);
                overlayHeight = imgOverlay.getHeight(this);
            }
            createAnimation();
        }
        repaint();
        do
            try
            {
                while(!isAnimating) 
                    Thread.sleep(500L);
                displayImage(gMain);
                if(++currImage == 12)
                    currImage = 0;
                if(++boatPhase == boatPhaseTotal)
                    boatPhase = 0;
                Thread.sleep(50L);
            }
            catch(InterruptedException _ex)
            {
                stop();
            }
        while(true);
    }

    private Image loadImage(String s)
    {
        Image image = null;
        MediaTracker mediatracker = new MediaTracker(this);
        image = getImage(getDocumentBase(), s);
        mediatracker.addImage(image, 0);
        try
        {
            mediatracker.waitForID(0);
            allLoaded = !mediatracker.isErrorAny();
        }
        catch(InterruptedException _ex) { }
        return image;
    }

    public boolean mouseUp(Event event, int i, int j)
    {
        super.mouseUp(event, i, j);
        if(m_HRef == null)
        {
            isAnimating = !isAnimating;
        } else
        {
            showStatus(String.valueOf(m_HRef));
            getAppletContext().showDocument(m_HRef, target);
        }
        return true;
    }

    public void paint(Graphics g)
    {
        if(allLoaded)
        {
            displayImage(g);
            return;
        } else
        {
            g.drawString("Loading images...", 10, 20);
            return;
        }
    }

    private void displayImage(Graphics g)
    {
        int i = (int)(((double)imgHeight * Math.sin((6.2831853070000001D * (double)boatPhase) / (double)boatPhaseTotal)) / 8D) - imgHeight / 8;
        if(!allLoaded)
            return;
        if(imgWave != null)
        {
            if(isRocking)
            {
                g.drawImage(imgWave, -currImage * imgWidth, imgHeight + i, this);
                g.drawImage(imgWave, (12 - currImage) * imgWidth, imgHeight + i, this);
                g.drawImage(imgReflect, 0, i - 1, this);
                return;
            }
            g.drawImage(imgWave, -currImage * imgWidth, imgHeight, this);
            g.drawImage(imgWave, (12 - currImage) * imgWidth, imgHeight, this);
            g.drawImage(imgReflect, 0, -1, this);
        }
    }

    public void createAnimation()
    {
        Image image = createImage(imgWidth, imgHeight + 1);
        Graphics g = image.getGraphics();
        g.drawImage(imgReflect, 0, 1, this);
        for(int i = 0; i < imgHeight >> 1; i++)
        {
            g.copyArea(0, i, imgWidth, 1, 0, imgHeight - i);
            g.copyArea(0, imgHeight - 1 - i, imgWidth, 1, 0, -imgHeight + 1 + (i << 1));
            g.copyArea(0, imgHeight, imgWidth, 1, 0, -1 - i);
        }

        imgWave = createImage(13 * imgWidth, imgHeight);
        gWave = imgWave.getGraphics();
        gWave.drawImage(image, 12 * imgWidth, 0, this);
        int j = 0;
        do
            makeWaves(gWave, j);
        while(++j < 12);
        g.drawImage(imgReflect, 0, 1, this);
        if(!"".equals(imgOverlayName))
            g.drawImage(imgOverlay, imgWidth - overlayWidth >> 1, imgHeight - (overlayHeight >> 1), this);
        imgReflect = image;
    }

    public void makeWaves(Graphics g, int i)
    {
        double d = (6.2831853071795862D * (double)i) / 12D;
        int j = (12 - i) * imgWidth;
        for(int k = 0; k < imgHeight; k++)
        {
            int l = (int)(((double)(imgHeight / 14) * ((double)k + 28D) * Math.sin((double)((imgHeight / 14) * (imgHeight - k)) / (double)(k + 1) + d)) / (double)imgHeight);
            if(k < -l)
                g.copyArea(12 * imgWidth, k, imgWidth, 1, -j, 0);
            else
                g.copyArea(12 * imgWidth, k + l, imgWidth, 1, -j, -l);
        }

        if(!"".equals(imgOverlayName))
            g.drawImage(imgOverlay, i * imgWidth + (imgWidth - overlayWidth >> 1), -overlayHeight >> 1, this);
    }

    private final String PARAM_IMAGE = "IMAGE";
    private final String PARAM_OVERLAY = "OVERLAY";
    private final String PARAM_HREF = "HREF";
    private final String PARAM_TARGET = "TARGET";
    private final String PARAM_ROCK = "ROCK";
    private final int NUM_FRAMES = 12;
    Thread m_Lake;
    private Graphics gMain;
    private Graphics gWave;
    private Image imgReflect;
    private Image imgOverlay;
    private Image imgWave;
    private int currImage;
    private int imgWidth;
    private int imgHeight;
    private int overlayWidth;
    private int overlayHeight;
    private boolean allLoaded;
    private boolean isAnimating;
    private String imgReflectName;
    private String imgOverlayName;
    private String target;
    private boolean isRocking;
    private URL m_HRef;
    private int boatPhase;
    private int boatPhaseTotal;
}

⌨️ 快捷键说明

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