飘扬的旗帜 站点:爱心种子小博士 关键字:飘扬的旗帜
|
飘扬的旗帜 import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
public class flags extends Applet
implements Runnable
{
public void init()
{
super.init();
setLayout(null);
registered = false;
appletcontrol = getAppletContext();
prepareVariables();
imagewidth = flag.getWidth(this);
imageheight = flag.getHeight(this);
imagepixels = new int[imagewidth * imageheight];
pixels = new int[d.width * d.height];
PixelGrabber pixelgrabber = new PixelGrabber(flag, 0, 0, imagewidth, imageheight, imagepixels, 0, imagewidth);
try
{
pixelgrabber.grabPixels();
}
catch(InterruptedException _ex) { }
g2 = bufferscreen.getGraphics();
alpha = 0.0D;
beta = PI / 3D;
}
public boolean mouseMove(Event event, int i, int j)
{
if(registered)
currentcolor = backgroundcolor2;
return true;
}
public boolean mouseExit(Event event, int i, int j)
{
if(registered)
currentcolor = backgroundcolor;
return true;
}
public boolean mouseDown(Event event, int i, int j)
{
if(registered)
{
URL url1;
try
{
url1 = new URL(url);
}
catch(MalformedURLException _ex)
{
System.out.println("Invalid URL");
return true;
}
if(target.compareTo("") != 0)
appletcontrol.showDocument(url1, target);
else
appletcontrol.showDocument(url1);
}
return true;
}
public boolean handleEvent(Event event)
{
return super.handleEvent(event);
}
public void checkreg()
{
String s = getParameter("JavaCity");
String s1 = getParameter("reg");
if(s.compareTo("http://www.chinawolf.com/~javacity/") == 0 && s1.compareTo("A00010") == 0)
{
registered = true;
return;
}
else
{
registered = false;
return;
}
}
public void prepareVariables()
{
checkreg();
resize(getIntegerParameter("width", 10), getIntegerParameter("height", 10));
sleeptime = getIntegerParameter("sleeptime", 10);
d = size();
String s = getParameter("bitmap");
url = getParameter("url");
target = getParameter("target");
bufferscreen = createImage(d.width, d.height);
tracker = new MediaTracker(this);
flag = getImage(getDocumentBase(), s);
tracker.addImage(flag, 0);
showStatus("正在装入图象");
try
{
tracker.waitForID(0);
}
catch(InterruptedException _ex) { }
showStatus("装入图象完成");
backgroundcolor = new Color(getIntegerParameter("background", 16));
backgroundcolor2 = new Color(getIntegerParameter("background2", 16));
currentcolor = backgroundcolor;
shadingstrength = getIntegerParameter("shadingstrength", 10);
waveamplitude = Math.max(20 - getIntegerParameter("waveamplitude", 10), 1);
}
public int getIntegerParameter(String s, int i)
{
String s1 = getParameter(s);
int j;
try
{
j = Integer.parseInt(s1, i);
}
catch(NumberFormatException _ex)
{
return 0;
}
return j;
}
public void start()
{
if(flags_thread == null)
{
flags_thread = new Thread(this);
flags_thread.start();
}
}
public void stop()
{
if(flags_thread != null && flags_thread.isAlive())
flags_thread.stop();
flags_thread = null;
}
public void paint(Graphics g1)
{
if(registered)
{
if(!creating && bufferimage != null)
g2.drawImage(bufferimage, 0, 0, this);
g1.drawImage(bufferscreen, 0, 0, this);
}
}
public void update(Graphics g1)
{
paint(g1);
}
public void createFlag()
{
int i = (currentcolor.getRGB() & 0xffffff) + 0xff000000;
for(int j = 0; j < d.width * d.height; j++)
pixels[j] = i;
alpha += 0.5D;
beta += 0.5D;
if(alpha > 2D * PI)
alpha = 0.0D;
if(beta > 2D * PI)
beta = 0.0D;
alpha1 = alpha;
beta1 = beta;
for(int l1 = imagewidth - 1; l1 > 0; l1--)
{
alpha1 += 0.10000000000000001D;
beta1 += 0.10000000000000001D;
if(alpha1 > 2D * PI)
alpha1 = 0.0D;
if(beta1 > 2D * PI)
beta1 = 0.0D;
int j1 = (int)((double)(l1 / waveamplitude) * Math.sin(alpha1) + (double)(l1 / waveamplitude) * Math.cos(beta1));
int k1 = (int)((double)(l1 / waveamplitude) * Math.sin(alpha1 - 1.0D) + (double)(l1 / waveamplitude) * Math.cos(beta1 - 1.0D));
for(int i2 = 0; i2 < imageheight; i2++)
if(i2 + l1 / waveamplitude + j1 < d.height && l1 < d.width)
{
int k = Math.min(Math.max(((imagepixels[l1 + i2 * imagewidth] & 0xff0000) >> 16) - k1 * shadingstrength, 0), 255);
int l = Math.min(Math.max(((imagepixels[l1 + i2 * imagewidth] & 0xff00) >> 8) - k1 * shadingstrength, 0), 255);
int i1 = Math.min(Math.max((imagepixels[l1 + i2 * imagewidth] & 0xff) - k1 * shadingstrength, 0), 255);
pixels[(i2 + l1 / waveamplitude + j1) * d.width + l1] = (k << 16) + (l << 8) + i1 + 0xff000000;
}
}
}
public void syncsleep(int i)
{
if(i > -1)
{
enabledtime = System.currentTimeMillis();
savedtime = i;
return;
}
try
{
Thread.sleep(Math.max((long)savedtime - (System.currentTimeMillis() - enabledtime), 4L));
return;
}
catch(InterruptedException _ex)
{
return;
}
}
public void run()
{
if(registered)
{
Graphics g1 = getGraphics();
do
{
syncsleep(sleeptime);
creating = true;
createFlag();
bufferimage = createImage(new MemoryImageSource(d.width, d.height, pixels, 0, d.width));
creating = false;
update(g1);
syncsleep(-1);
System.gc();
}
while(true);
}
g2.setColor(Color.black);
g2.fillRect(0, 0, d.width, d.height);
Font font = new Font("TimesRoman", 0, 12);
g2.setFont(font);
g2.setColor(Color.yellow);
g2.drawString("你必须注册 ", 0, 12);
g2.drawString("在以下位置:", 0, 24);
g2.drawString("www.chinawolf.com/~javacity/", 0, 36);
}
public flags()
{
PI = 3.1415926535000001D;
}
protected MediaTracker tracker;
private Thread flags_thread;
private int sleeptime;
private Image bufferscreen;
private Image bufferimage;
private Image flag;
private Dimension d;
double PI;
double alpha;
double beta;
double alpha1;
double beta1;
private Color backgroundcolor;
private Color backgroundcolor2;
private Color currentcolor;
AppletContext appletcontrol;
private Graphics g;
private Graphics g2;
private boolean registered;
String url;
String target;
private int imagepixels[];
private int pixels[];
private int imagewidth;
private int imageheight;
private boolean creating;
private int savedtime;
private long enabledtime;
private int shadingstrength;
private int waveamplitude;
} |
|
|
|