import java.awt.*; import java.awt.image.*; import java.net.*; import java.applet.*; import java.util.*; public class Rollover extends Applet { public static final int end = 2147483647; static Panel p1, p2; static int diff; static Image i; public void paint(Graphics g) { int now = (int) (java.lang.System.currentTimeMillis() / 1000); int x, y, s1x, s1y, s2x, s2y, ix, iy; FontMetrics fm; String s1, s2; Dimension d; Font f; diff = end - now; s1 = "" + getYears() + " Years, " + getDays() + " Days"; s2 = "" + getFormattedHours() + ":" + getFormattedMinutes() + ":" + getFormattedSeconds(); d = getSize(); x = d.width; y = d.height; if ((checkImage(i, this) & ImageObserver.ALLBITS) != 0) { if((checkImage(i, this) & ImageObserver.WIDTH) != 0) { if((checkImage(i, this) & ImageObserver.HEIGHT) != 0) { ix = (x / 2) - i.getWidth(this) / 2; iy = (y / 2) - i.getHeight(this) / 2; g.drawImage(i, ix, iy, this); } } } else g.drawString("Loading image...", 10, 15); // Draw top string fm = g.getFontMetrics(); s1x = (x / 2) - (fm.stringWidth(s1) / 2); s1y = ((y / 4) * 1) + fm.getHeight() / 2; g.drawString(s1, s1x, s1y); // Draw bottom string f = new Font("SansSerif", java.awt.Font.PLAIN, 48); g.setFont(f); fm = g.getFontMetrics(); s2x = (x / 2) - (fm.stringWidth(s2) / 2); s2y = ((y / 4) * 3) + fm.getHeight() / 2; g.drawString(s2, s2x, s2y); try { java.lang.Thread.sleep(1000); } catch (InterruptedException e) { System.out.println(e.toString()); } repaint(); } public String getFormattedSeconds() { int sec = getSeconds(); if(sec <= 9) return "0" + sec; else return "" + sec; } public int getSeconds() { return diff % 60; } public int getMinutes() { int tmp; tmp = diff; tmp %= (60 * 60); return tmp / (60); } public String getFormattedMinutes() { int min = getMinutes(); if(min <= 9) return "0" + min; else return "" + min; } public int getHours() { int tmp; tmp = diff; tmp %= (60 * 60 * 24); return tmp / (60 * 60); } public String getFormattedHours() { int hrs = getHours(); if(hrs <= 9) return "0" + hrs; else return "" + hrs; } public int getDays() { int tmp; tmp = diff; tmp %= (60 * 60 * 24 * 365); return tmp / (60 * 60 * 24); } public int getYears() { return diff / (60 * 60 * 24 * 365); } public void init() { try { i = getImage(new URL("http://lightconsulting.com/~thalakan/images/endisnear.png")); prepareImage(i, this); } catch (Exception e) { System.out.println(e.toString()); } } }