TAG:
高手们请帮我看下这两个JAVA APPLET程序,简单解释一下急用 import java.applet.Applet; import java.awt.*; import java.awt.image.MemoryImageSource; import java.awt.image.PixelGrabber; import java.io.PrintStream; public class SpotLight extends Applet implements Runnable { private String Text; private Image offI; private int pX; private int pY; private int width; private int height; private int fadeWidth; private Thread thread; private int radius; private int shiftFrom; private int shiftTo; private int delay; private int step; private int hpadding; private int vpadding; private int FontSize; private boolean isVacuum; public void init() { start2(); } public void start() { if(thread == null) { thread = new Thread(this); thread.start(); } } public void stop() { if(thread != null) { thread.stop(); doStop(); thread = null; } } public void run() { do { Efficinet(); try { Thread.sleep(delay); } catch(InterruptedException _ex) { } } while(true); } public void doStop() { System.gc(); } public void start2() { String s = new String(""); if((s = getParameter("Text")) != null) Text = s; else Text = "Text=null"; setFont(new Font("Helvetica", 1, FontSize)); if((s = getParameter("textcolor")) != null) setForeground(new Color(Integer.parseInt(s, 16))); else setForeground(new Color(0xe99b00)); if((s = getParameter("bgcolor")) != null) setBackground(new Color(Integer.parseInt(s, 16))); else setBackground(Color.black); if((s = getParameter("shiftFrom")) != null) shiftFrom = Integer.parseInt(s, 16); if((s = getParameter("shiftTo")) != null) shiftTo = Integer.parseInt(s, 16); if((s = getParameter("radius")) != null) radius = Integer.parseInt(s); fadeWidth = radius * 2 + 1; if((s = getParameter("hpadding")) != null) hpadding = Integer.parseInt(s); if((s = getParameter("vpadding")) != null) vpadding = Integer.parseInt(s); if((s = getParameter("isvacuum")) != null && Integer.parseInt(s) == 1) isVacuum = true; if((s = getParameter("delay")) != null) delay = Integer.parseInt(s); if((s = getParameter("step")) != null) step = Integer.parseInt(s); offI = do3DText(Text); } public void paint(Graphics g) { getGraphics().clearRect(0, 0, size().width - 1, size().height - 1); } public void repaint() { } public void update(Graphics g) { } Image do3DText(String s) { int i = getGraphics().getFontMetrics().stringWidth(s); int j = getGraphics().getFontMetrics().getHeight(); width = i + 2 * hpadding + 1; height = j + 2 * vpadding + 1; pX = 0; pY = height / 2; Image image = createImage(width, height); Graphics g = image.getGraphics(); g.setFont(getGraphics().getFont()); g.setColor(getBackground()); g.fillRect(0, 0, width, height); g.setColor(new Color(~getBackground().getRGB())); g.drawString(s, hpadding, (j - getGraphics().getFontMetrics().getDescent()) + vpadding); g.setColor(getForeground()); g.drawString(s, hpadding - 1, ((j - getGraphics().getFontMetrics().getDescent()) + vpadding) - 1); return image; } public void Efficinet() { int i = radius * radius; pX += step; if(pX > width - radius) { if(Math.random() < 0.5D) { step = -step; pX += step; } else { pX = radius; } } else if(pX < radius) if(Math.random() < 0.5D) { step = -step; pX += step; } else { pX = width - radius; } int k3; if(isVacuum) k3 = getBackground().getRGB(); else k3 = 0; int j2 = 0; int ai[] = new int[width * height]; int ai1[] = new int[fadeWidth * fadeWidth]; PixelGrabber pixelgrabber = new PixelGrabber(offI, 0, 0, width, height, ai, 0, width); try { pixelgrabber.grabPixels(); } catch(InterruptedException _ex) { System.err.println("interrupted waiting for pixels!"); } int ai2[] = new int[3]; int ai3[] = new int[3]; int ai4[] = new int[3]; int l = 0; int j1 = 0; for(int l1 = 255; l < 3; l1 <<= 8) { ai2[l] = (shiftFrom & l1) >> j1; ai3[l] = (shiftTo & l1) >> j1; ai4[l] = ai3[l] - ai2[l]; l++; j1 += 8; } for(int j3 = -fadeWidth + radius; j3 < radius; j3++) { for(int i3 = -fadeWidth + radius; i3 < radius; i3++) { int j = pX + i3 + (pY + j3) * width; if(j >= 0 && j < width * height) { j = ai[j]; int k2 = i3 * i3 + j3 * j3; if(k2 <= i && j != k3) { int k = 0xff000000; double d = (1.0D - Math.sqrt(k2) / (double)radius) / 1.0000009999999999D; int i1 = 0; int k1 = 0; for(int i2 = 255; k1 < 24; i2 <<= 8) { nt l2 = ((j & i2) >> k1) + ai2[i1] + (int)(d * (double)ai4[i1]); k |= (l2 <= 255 ? l2 : 255) << k1; i1++; k1 += 8; } ai1[j2++] = k; } else { ai1[j2++] = j; } } else { ai1[j2++] = 0xff000000; } } } Image image1 = createImage(new MemoryImageSource(fadeWidth, fadeWidth, ai1, 0, fadeWidth)); Image image = createImage(width, height); image.getGraphics().drawImage(offI, 0, 0, this); image.getGraphics().drawImage(image1, (pX - fadeWidth) + radius, (pY - fadeWidth) + radius, this); int l3 = size().width; int i4 = size().height; getGraphics().clearRect(0, 0, l3 - 1, (i4 - height) / 2 - 1); getGraphics().clearRect(0, (i4 + height) / 2, l3 - 1, i4 - 1); getGraphics().clearRect(0, 0, (l3 - width) / 2 - 1, i4 - 1); getGraphics().clearRect((l3 + width) / 2, 0, l3 - 1, i4 - 1); getGraphics().drawImage(image, (size().width - width) / 2, (size().height - height) / 2, this); } public SpotLight() { radius = 25; step = 8; hpadding = 30; FontSize = 30; isVacuum = false; } } (iwgh) |