📄 shutter.java
字号:
import java.awt.*;
import java.applet.*;
import java.io.*;
import java.awt.image.*;
public class Shutter extends Applet implements Runnable
{
private Image myIMG[],myImageToShow;
private MediaTracker imageTracker;
private int myIMGWidth,myIMGHeight,totalImage = 5,currentImage,nextImage;
private Thread mythread;
private int delay;
private int totalPix,pix1[],pix2[],pix3[],pix4[],pix5[],pixA[],pixB[];
public void init()
{
this.setBackground(Color.black);
myIMG = new Image[totalImage];
imageTracker = new MediaTracker(this);
String s = new String("");
for(int i=0; i<totalImage; i++)
{
s = getParameter("image" + (i+1));
myIMG[i] = getImage(getCodeBase(),s);
imageTracker.addImage(myIMG[i],0);
}
try
{
imageTracker.waitForID(0);
}
catch(InterruptedException e)
{
}
if(getParameter("delay") == null)
{
delay = 3000;
}
else
{
delay = Integer.parseInt(getParameter("delay"));
}
myIMGWidth = myIMG[0].getWidth(this);
myIMGHeight = myIMG[0].getHeight(this);
totalPix = myIMGWidth*myIMGHeight;
pix1 = new int[totalPix];
PixelGrabber PG1 = new PixelGrabber(myIMG[0],0,0,myIMGWidth,myIMGHeight,pix1,0,myIMGWidth);
try
{
PG1.grabPixels();
}
catch(InterruptedException ex)
{
}
pix2 = new int[totalPix];
PixelGrabber PG2 = new PixelGrabber(myIMG[1],0,0,myIMGWidth,myIMGHeight,pix2,0,myIMGWidth);
try
{
PG2.grabPixels();
}
catch(InterruptedException ex)
{
}
pix3 = new int[totalPix];
PixelGrabber PG3 = new PixelGrabber(myIMG[2],0,0,myIMGWidth,myIMGHeight,pix3,0,myIMGWidth);
try
{
PG3.grabPixels();
}
catch(InterruptedException ex)
{
}
pix4 = new int[totalPix];
PixelGrabber PG4 = new PixelGrabber(myIMG[3],0,0,myIMGWidth,myIMGHeight,pix4,0,myIMGWidth);
try
{
PG4.grabPixels();
}
catch(InterruptedException ex)
{
}
pix5 = new int[totalPix];
PixelGrabber PG5 = new PixelGrabber(myIMG[4],0,0,myIMGWidth,myIMGHeight,pix5,0,myIMGWidth);
try
{
PG5.grabPixels();
}
catch(InterruptedException ex)
{
}
currentImage = 0;
pixA = new int[totalPix];
pixB = new int[totalPix];
myImageToShow = myIMG[0];
mythread = new Thread(this);
mythread.start();
}
public void paint(Graphics g)
{
g.drawImage(myImageToShow,0,0,this);
}
public void update(Graphics g)
{
paint(g);
}
public void run()
{
if(mythread == null)
{
mythread = new Thread(this);
mythread.start();
}
while(true)
{
try
{
mythread.sleep(delay);
nextImage = ((currentImage+1)%totalImage);
if (currentImage ==0)
{
System.arraycopy(pix1,0,pixA,0,totalPix);
System.arraycopy(pix2,0,pixB,0,totalPix);
myImageToShow = createImage(new MemoryImageSource(myIMGWidth,myIMGHeight,pixA,0,myIMGWidth));
repaint();
}
if (currentImage ==1)
{
System.arraycopy(pix2,0,pixA,0,totalPix);
System.arraycopy(pix3,0,pixB,0,totalPix);
myImageToShow = createImage(new MemoryImageSource(myIMGWidth,myIMGHeight,pixA,0,myIMGWidth));
repaint();
}
if (currentImage ==2)
{
System.arraycopy(pix3,0,pixA,0,totalPix);
System.arraycopy(pix4,0,pixB,0,totalPix);
myImageToShow = createImage(new MemoryImageSource(myIMGWidth,myIMGHeight,pixA,0,myIMGWidth));
repaint();
}
if (currentImage ==3)
{
System.arraycopy(pix4,0,pixA,0,totalPix);
System.arraycopy(pix5,0,pixB,0,totalPix);
myImageToShow = createImage(new MemoryImageSource(myIMGWidth,myIMGHeight,pixA,0,myIMGWidth));
repaint();
}
if (currentImage ==4)
{
System.arraycopy(pix5,0,pixA,0,totalPix);
System.arraycopy(pix1,0,pixB,0,totalPix);
myImageToShow = createImage(new MemoryImageSource(myIMGWidth,myIMGHeight,pixA,0,myIMGWidth));
repaint();
}
while(true)
{
for(int i=0; i<(int)(myIMGHeight/10);i++)
{
try
{
mythread.sleep(20);
for(int j=0; j<myIMGHeight; j+=(int)(myIMGHeight/10))
{
for(int k=0; k<myIMGWidth; k++)
{
pixA[myIMGWidth*(j+i) + k] = pixB[myIMGWidth*(j+i) + k];
}
}
}
catch(InterruptedException e){}
myImageToShow = createImage(new MemoryImageSource(myIMGWidth,myIMGHeight,pixA,0,myIMGWidth));
repaint();
}
break;
}
currentImage = nextImage;
repaint();
}
catch(InterruptedException e)
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -