import java.awt.*;
import java.lang.String;
import java.applet.Applet;
import java.applet.AppletContext;
import java.net.MalformedURLException;
import java.net.URL;
public class Lake extends Applet implements Runnable
{
Thread m_Lake;
private Graphics m_Graphics;
private Graphics m_WaveGraphics;
private Image m_Image;
private Image m_Overlay;
private Image m_WaveImage;
private int m_nCurrImage;
private int m_nImgWidth;
private int m_nImgHeight;
private int m_nOvlWidth;
private int m_nOvlHeight;
private boolean m_fAllLoaded;
private boolean m_tAnimate;
private final int NUM_FRAMES = 12;
private String m_ImageName;
private String m_OverlayName;
private URL m_HRef;
private String m_Frame;
private final String PARAM_image = "image";
private final String PARAM_overlay = "overlay";
private final String PARAM_href = "href";
private final String PARAM_target = "target";
public void createAnimation()
{
Image image = createImage(m_nImgWidth, m_nImgHeight + 1);
Graphics g = image.getGraphics();
g.drawImage(m_Image, 0, 1, this);
for (int i = 0; i < m_nImgHeight >> 1; i++)
{
g.copyArea(0, i, m_nImgWidth, 1, 0, m_nImgHeight - i);
g.copyArea(0, m_nImgHeight - 1 - i, m_nImgWidth, 1, 0, -m_nImgHeight + 1 + (i << 1));
g.copyArea(0, m_nImgHeight, m_nImgWidth, 1, 0, -1 - i);
}
m_WaveImage = createImage(13 * m_nImgWidth, m_nImgHeight);
m_WaveGraphics = m_WaveImage.getGraphics();
m_WaveGraphics.drawImage(image, 12 * m_nImgWidth, 0, this);
int j = 0;
do
makeWaves(m_WaveGraphics, j);
while (++j < 12);
g.drawImage(m_Image, 0, 1, this);
if (!"".equals(m_OverlayName))
g.drawImage(m_Overlay, m_nImgWidth - m_nOvlWidth >> 1, m_nImgHeight - (m_nOvlHeight >> 1), this);
m_Image = image;
}
public void start()
{
if (m_Lake == null)
{
m_Lake = new Thread(this);
m_Lake.start();
}
}
public String[][] getParameterInfo()
{
String aastring[][] = { { "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" } };
return aastring;
}
public void stop()
{
if (m_Lake != null)
{
m_Lake.stop();
m_Lake = null;
}
}
private void displayImage(Graphics g)
{
if (!m_fAllLoaded)
return;
if (m_WaveImage != null)
{
g.drawImage(m_WaveImage, -m_nCurrImage * m_nImgWidth, m_nImgHeight, this);
g.drawImage(m_WaveImage, (12 - m_nCurrImage) * m_nImgWidth, m_nImgHeight, this);
}
g.drawImage(m_Image, 0, -1, this);
}
public String getAppletInfo()
{
return "Name: Lake v3.0\r\n" + "Author: David Griffiths\r\n" + "Created with Microsoft Visual J++ Version 1.0";
}
public boolean mouseUp(Event event, int i, int j)
{
super.mouseUp(event, i, j);
if (m_HRef == null)
m_tAnimate = !m_tAnimate;
else
{
showStatus("" + m_HRef);
getAppletContext().showDocument(m_HRef, m_Frame);
}
return true;
}
public void run()
{
m_nCurrImage = 0;
if (!m_fAllLoaded)
{
repaint();
m_Graphics = getGraphics();
MediaTracker mediaTracker = new MediaTracker(this);
m_Image = getImage(getDocumentBase(), m_ImageName);
if (!"".equals(m_OverlayName))
m_Overlay = getImage(getDocumentBase(), m_OverlayName);
mediaTracker.addImage(m_Image, 0);
if (!"".equals(m_OverlayName))
mediaTracker.addImage(m_Overlay, 1);
try
{
mediaTracker.waitForAll();
m_fAllLoaded = !mediaTracker.isErrorAny();
}
catch (InterruptedException e1)
{
}
if (!m_fAllLoaded)
{
stop();
m_Graphics.drawString("Error loading images!", 10, 40);
return;
}
m_nImgWidth = m_Image.getWidth(this);
m_nImgHeight = m_Image.getHeight(this);
if (!"".equals(m_OverlayName))
{
m_nOvlWidth = m_Overlay.getWidth(this);
m_nOvlHeight = m_Overlay.getHeight(this);
}
createAnimation();
}
repaint();
while (true)
{
try
{
while (!m_tAnimate)
Thread.sleep(500);
displayImage(m_Graphics);
if (++m_nCurrImage == 12)
m_nCurrImage = 0;
Thread.sleep(50);
}
catch (InterruptedException e2)
{
stop();
}
}
}
public void makeWaves(Graphics g, int i1)
{
double d = 6.28319 * i1 / 12;
int j = (12 - i1) * m_nImgWidth;
for (int i2 = 0; i2 < m_nImgHeight; i2++)
{
int k = (int)((double)(m_nImgHeight / 14) * ((double)i2 + 28) * Math.sin((double)(m_nImgHeight / 14 * (m_nImgHeight - i2)) / (i2 + 1) + d) / m_nImgHeight);
if (i2 < -k)
g.copyArea(12 * m_nImgWidth, i2, m_nImgWidth, 1, -j, 0);
else
g.copyArea(12 * m_nImgWidth, i2 + k, m_nImgWidth, 1, -j, -k);
}
if (!"".equals(m_OverlayName))
g.drawImage(m_Overlay, i1 * m_nImgWidth + (m_nImgWidth - m_nOvlWidth >> 1), -m_nOvlHeight >> 1, this);
}
public Lake()
{
m_tAnimate = true;
m_ImageName = "";
m_OverlayName = "";
m_Frame = "_self";
}
public void destroy()
{
}
public void init()
{
String string = getParameter("image");
if (string != null)
m_ImageName = string;
string = getParameter("overlay");
if (string != null)
m_OverlayName = string;
string = getParameter("href");
if (string != null)
{
try
{
m_HRef = new URL(getDocumentBase(), string);
}
catch (MalformedURLException e)
{
getAppletContext().showStatus("Bad URL: " + string);
return;
}
}
string = getParameter("target");
if (string != null)
m_Frame = string;
}
public void paint(Graphics g)
{
if (m_fAllLoaded)
{
displayImage(g);
return;
}
g.drawString("Loading images...", 10, 20);
}
}
评论0
最新资源