import java.applet.*;
import java.awt.*;
import java.lang.Integer;
public class dig extends Applet implements Animation {
private int dig;
int i;
byte locstate[][]={{1,3,3,1,3,3,0}
,{0,3,3,0,2,2,0},{1,3,2,1,3,2,1},{1,3,3,1,2,2,1}
,{0,3,3,0,2,3,1},{1,2,3,1,2,3,1},{1,2,3,1,3,3,1}
,{1,3,3,0,2,2,0},{1,3,3,1,3,3,1},{1,3,3,0,2,3,1}
,{1,3,3,0,3,3,1},{0,2,3,1,3,3,1},{1,2,2,1,3,3,0}
,{0,3,3,1,3,2,1},{1,2,2,1,3,3,1},{1,2,2,0,3,3,1}};
byte xoff[]={11,43,43,11,0,0,11};
byte yoff[]={0,8,42,68,42,8,34};
Dimension size;
Image buffer;
Graphics bufferGraphics;
AnimationTimer timer = new AnimationTimer(this, 500);
public void init(){
setBackground (Color.black);
size=this.size();
buffer=this.createImage(size.width, size.height);
bufferGraphics = buffer.getGraphics();
}
public void start() {
timer.start_animation();
dig=0;
}
public void paint(Graphics g) {
if (buffer != null)
g.drawImage(buffer, 0,0,this);
}
public void update(Graphics g){
if (buffer != null){
Image horoff = getImage(getCodeBase(), "horoff.jpg");
Image virtoff = getImage(getCodeBase(), "virtoff.jpg");
Image virton = getImage(getCodeBase(), "virton.jpg");
Image horon = getImage(getCodeBase(), "horon.jpg");
Image led = getImage(getCodeBase(), "led2.jpg");
Font font = new Font("Helvetica", Font.BOLD, 10);
bufferGraphics.setFont(font);
for (i=0;i<=6;i++){
if(locstate[dig][i]==0)
bufferGraphics.drawImage (horoff, xoff[i],yoff[i], this);
else if (locstate[dig][i]==1)
bufferGraphics.drawImage (horon, xoff[i],yoff[i], this);
else if (locstate[dig][i]==2)
bufferGraphics.drawImage (virtoff, xoff[i],yoff[i], this);
else if (locstate[dig][i]==3)
bufferGraphics.drawImage (virton, xoff[i],yoff[i], this);
g.drawImage(buffer,0,0,this);
}
}
}
public void animate (){
dig++;
if(dig==16)
dig=0;
repaint();
}
public void stop() { timer.start_animation(); }
}
interface Animation { public void animate(); }
class AnimationTimer extends Thread {
Animation animation;
int delay;
public AnimationTimer(Animation animation, int delay) {
this.animation = animation;
this.delay = delay;
}
public void start_animation() {
if (isAlive()) super.resume();
else start();
}
public void pause_animation() { suspend(); }
public void run () {
for(;;) {
animation.animate();
try { Thread.sleep(delay); } catch (InterruptedException e) { ; }
}
}
}
|