1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
public class Counter extends Applet {
private Integer startValue;
private Integer segonde;
private Integer mlsegonde;
private Integer IC;
private int Value;
private int inc;
private int seg;
private int mls;
private int[][] at = {{3,3,22,33},{31,3,22,33},{57,3,22,33},{85,3,22,33},{111,3,22,33},{139,3,22,33},{165,3,22,33},{193,3,22,33},{219,3,22,33},{247,3,22,33}};
private String startDate;
private String increment;
private SimpleDateFormat form;
private Image image;
private Image bg;
public Counter()
{
setFont(new Font("Courrier",Font.BOLD,14));
setForeground(Color.black);
}
public void init()
{
}
public void start()
{
Value = startValue.parseInt(getParameter("startValue"));
startDate = getParameter("startDate");
increment = getParameter("increment");
image = getImage(getCodeBase(), getParameter("fontImage"));
bg = getImage(getCodeBase(), getParameter("bgImage"));
mls = mlsegonde.parseInt(increment.substring(increment.indexOf(":")+1, increment.length()));
seg = segonde.parseInt(increment.substring(increment.indexOf(" ")+1, increment.indexOf(":")));
inc = IC.parseInt(increment.substring(0, increment.indexOf(" ")));
}
public void update(Graphics g) {
g.clearRect(0, 0, getSize().width, getSize().height);
g.drawImage(bg, 0, 0, this);
init();
repaint();
}
public void paint(Graphics g)
{
int Tdate;
int Tstart;
int Tres;
form = new SimpleDateFormat("dd MMM yyyy kk:mm:ss z");
Date date= new Date();
try {
date = form.parse(startDate);
} catch (ParseException ex) {
}
String pli="";
Date tmp = new Date();
if (date.before(tmp)) {
Tdate = (int) tmp.getTime();
Tstart = (int) date.getTime();
Tres = Tdate - Tstart;
Value += inc * (Tres / (seg*1000 + mls));
}
else
{
while (!date.equals(tmp))
tmp = new Date();
}
boolean i = true;
String ch1 = "";
while (i) {
ch1 = ch1.valueOf(Value);
g.clearRect(0, 0, getSize().width, getSize().height);
g.drawImage(bg, 0, 0, this);
int posx = getSize().width/2 - (ch1.length()*((at[0][2] / 2) + 2)) - 5;
int posy = (getSize().height/2) - (at[0][3]/2);
if (ch1.length() != 0)
{
for (int o = 0; o < ch1.length(); o++) {
if (ch1.charAt(o) == '0') {
g.drawImage(image, posx, posy, (posx+at[0][2]), (posy+at[0][3]), at[0][0], at[0][1], (at[0][0]+at[0][2]), (at[0][1]+at[0][3]), this);
posx += at[0][2];
}
else
{
g.drawImage(image, posx, posy, (posx+at[0][2]), (posy+at[0][3]), at[0][0], at[0][1], (at[0][0]+at[0][2]), (at[0][1]+at[0][3]), this);
posx += at[0][2];
}
Value += inc;
try {Thread.sleep(seg * 1000 + mls);}
catch (InterruptedException signal) {g.drawString("FAIL!", 10, 15);}
}
}
} |
Partager