Applet程式 |
尚未結案
|
jack910179
一般會員 ![]() ![]() 發表:1 回覆:0 積分:0 註冊:2005-06-08 發送簡訊給我 |
程式碼:
import java.applet.Applet;
import java.awt.*;
import java.awt.image.ImageObserver;
import java.io.PrintStream; public class ripple extends Applet
implements Runnable
{ public void init()
{
if(!dispCopy)
{
System.out.println("Ripple v 1.0 for Java");
System.out.println("Copyright (c) David Griffiths, 1996. All rights reserved.");
System.out.println("For more information visit http://www.demon.co.uk/davidg,");
System.out.println("or contact: dgriffiths@msn.com");
dispCopy = true;
}
setBackground(Color.white);
origImg = getImage(getDocumentBase(), getParameter("image"));
borderGap = "on".equals(getParameter("bordergap"));
w1 = origImg.getWidth(this);
h1 = origImg.getHeight(this);
if(h1 > 0 && w1 > 0)
stopIt = false;
period = Integer.parseInt(getParameter("period"));
frames = Integer.parseInt(getParameter("frames"));
} public void start()
{
if(nick == null)
{
nick = new Thread(this);
nick.start();
}
} public void stop()
{
if(nick != null)
{
nick.stop();
nick = null;
}
} public boolean imageUpdate(Image image, int i, int j, int k, int l, int i1)
{
boolean flag = true;
if((i & 2) > 0)
h1 = i1;
if((i & 1) > 0)
w1 = l;
if((i & 0x20) > 0)
imLoaded = true;
if(imLoaded && w1 > 0 && h1 > 0)
{
stopIt = false;
flag = false;
}
return flag;
} public void rotateImage(Graphics g)
{
shearX(g);
shearY(g);
} public void shearX(Graphics g)
{
for(int i = 0; i < h1; i )
{
double d = (double)(period >> 1) * Math.sin((double)i / (double)period (6.2831853071795862D * (double)phase) / (double)frames);
g.copyArea(0, i, w1, 1, (int)d, 0);
if(borderGap)
{
g.drawLine((int)d, i, 0, i);
g.drawLine((int)d w1, i, w1, i);
}
} } public void shearY(Graphics g)
{
for(int i = 0; i < w1; i )
{
double d = (double)(period >> 1) * Math.sin((double)i / (double)period (6.2831853071795862D * (double)phase) / (double)frames);
g.copyArea(i, 0, 1, h1, 0, (int)d);
if(borderGap)
{
g.drawLine(i, (int)d, i, 0);
g.drawLine(i, (int)d h1, i, h1);
}
} } public void run()
{
while(nick != null)
{
try
{
Thread.sleep(50L);
}
catch(InterruptedException _ex) { }
frameNo = (frameNo 1) % frames;
repaint();
}
} public void update(Graphics g)
{
paint(g);
} public void paint(Graphics g)
{
if(!stopIt)
{
stopIt = true;
createIt();
}
if(finImg != null)
{
g.drawImage(finImg, 0, -frameNo * h1, this);
g.drawImage(finImg, 0, (frames - frameNo) * h1, this);
return;
} else
{
g.drawImage(origImg, 0, 0, this);
return;
}
} public void createIt()
{
backImg = createImage(w1, h1);
backG = backImg.getGraphics();
finImg = createImage(w1, frames * h1);
finG = finImg.getGraphics();
backG.setColor(Color.white);
for(phase = 0; phase < frames; phase )
{
backG.drawImage(origImg, 0, 0, this);
rotateImage(backG);
finG.drawImage(backImg, 0, phase * h1, this);
} } public ripple()
{
frames = 12;
period = 50;
stopIt = true;
borderGap = true;
imLoaded = false;
} static boolean dispCopy;
Image origImg;
Image backImg;
Image finImg;
int w1;
int h1;
Graphics backG;
Graphics finG;
int phase;
Thread nick;
int frameNo;
int frames;
int period;
boolean stopIt;
boolean borderGap;
boolean imLoaded;
}
-----------------------------------------------------------------------------------
origImg = getImage(getDocumentBase(), getParameter("image"));
borderGap = "on".equals(getParameter("bordergap"));
w1 = origImg.getWidth(this);
h1 = origImg.getHeight(this);
if(h1 > 0 && w1 > 0)
stopIt = false;
period = Integer.parseInt(getParameter("period"));
frames = Integer.parseInt(getParameter("frames"));
這一段要怎麼解釋啊....看很久都看不懂???
拜託各位大大教一下
|
neoart
版主 ![]() ![]() ![]() ![]() ![]() 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
kenon0425
一般會員 ![]() ![]() 發表:5 回覆:8 積分:2 註冊:2004-04-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |