/* Year2000 applet by James Inge.
 *
 * 21/12/97
 *
 * This gives the time remaining (months, days, hours, mins, secs) until the year 2000.
 * To use, enter following HTML segment:
 *		<APPLET ALIGN=middle CODE="Year2000.class" WIDTH=370 HEIGHT=18></APPLET>
 */
 
import java.awt.Graphics;
import java.awt.Font;
import java.util.Date;

public class Year2000 extends java.applet.Applet implements Runnable {
// Runnable lets me multithread, for refresh to work better.

	Thread runner;

	public void start() {
		if (runner == null) {
			runner = new Thread(this);
			runner.start();
		}
	}

	public void stop() {
		if (runner != null) {
			runner.stop();
			runner = null;
		}
	}

	public void run() {
	//	While running, refresh every half sec.
		
		while (true) {
			repaint();
			try{ Thread.sleep(500); }
			catch (InterruptedException e) { }
		}
	}

	public void init() {
	}
	
	public void paint(Graphics g) {
	//	Refresh the screen, updating the time.
		
		int years, months, days, hours, minutes, seconds;
		String timeLeft;

		Date now = new Date();
		years   = 99 - now.getYear();
		months  = 11 - now.getMonth();
		days    = 31 - now.getDate();
		hours   = 23 - now.getHours();
		minutes = 59 - now.getMinutes();
		seconds = 59 - now.getSeconds();

		timeLeft = "" + years;
		if (years == 1) {
			timeLeft += " year, ";
		} else {
			timeLeft += " years, ";
		}
		timeLeft += months + " months, " + days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds";

		if ((years < 1 ) && (months < 3)) {
			timeLeft += "!";
			if (days < 7) {
				timeLeft += "!!";
			}
		}
		else {
			timeLeft +=".";
		}

		if (years < 0 ) {
			timeLeft = "The third Millenium is upon us! ";
		}
		
		g.setFont(new Font("TimesRoman", Font.PLAIN, 15));
		g.drawString( timeLeft, 1, 15 );
	}
}

