Die Zahl stimmt natürlich hinten und vorne nicht.
Aber irgendeinen Zähler braucht
schließlich jede Homepage ;-).
Meiner ist ein kleines Java-Applet und funktioniert
folglich nur mit einem Java-fähigen Browser.
Hier ist der Source-Code:
import java.applet.*;
import java.awt.*;
import java.util.Date;
public class SillyCounter extends Applet implements Runnable {
Image digits, osi;
Graphics osg;
String imageName = "digits.gif";
Date today = new Date();
Thread timerThread = null;
int count;
public void init() {
// load image
MediaTracker mt = new MediaTracker(this);
digits = getImage(getCodeBase(), imageName);
mt.addImage(digits, 0);
try { mt.waitForID(0); } catch (InterruptedException e) {}
if (mt.isErrorID(0)) showStatus("Error loading Image"+imageName);
// initialization of graphics
osi = createImage(90,20);
osg = osi.getGraphics();
resize(90, 20);
// get starting value for count
count = (int)(((today.getTime()-new Date(96,6,1,0,0,0).getTime())/1000)%1000000);
if (count < 0) count = -count;
// status message
showStatus("Applet SillyCounter initialized");
}
public void start () {
if (timerThread == null)
timerThread = new Thread(this, "Timer");
if (!timerThread.isAlive())
timerThread.start();
// status message
showStatus("Applet SillyCounter started");
}
public void stop() {
if (timerThread != null) {
timerThread.stop();
timerThread = null;
}
// status message
showStatus("Applet SillyCounter stopped");
}
public void destroy() {
// status message
showStatus("Applet SillyCounter destroyed");
}
public void run() {
while (true) {
try {
timerThread.sleep(1000);
} catch (InterruptedException e) {}
count++;
repaint();
}
}
public void paint(Graphics g) {
update(g);
}
public void update(Graphics g) {
Graphics tmp;
int tmpcount = count;
tmp = osg.create(0,0,15,20);
tmp.drawImage(digits,0-15*(tmpcount/100000),0,this);
tmp.dispose();
tmpcount %= 100000;
tmp = osg.create(15,0,15,20);
tmp.drawImage(digits,0-15*(tmpcount/10000),0,this);
tmp.dispose();
tmpcount %= 10000;
tmp = osg.create(30,0,15,20);
tmp.drawImage(digits,0-15*(tmpcount/1000),0,this);
tmp.dispose();
tmpcount %= 1000;
tmp = osg.create(45,0,15,20);
tmp.drawImage(digits,0-15*(tmpcount/100),0,this);
tmp.dispose();
tmpcount %= 100;
tmp = osg.create(60,0,15,20);
tmp.drawImage(digits,0-15*(tmpcount/10),0,this);
tmp.dispose();
tmpcount %= 10;
tmp = osg.create(75,0,15,20);
tmp.drawImage(digits,0-15*tmpcount,0,this);
tmp.dispose();
g.drawImage(osi, 0, 0, null);
}
}
Immer wieder gerne gehört: "wozu Kommentare, geht doch alles aus dem Source-Code hervor!"