import java.util.*; import java.awt.*; import java.applet.*; import java.net.*; import java.text.*; import javax.swing.*; public class countdown extends Applet implements Runnable { private URL dest; private Date theDate = new Date(); private String saying, font; private String path = ""; private int i = 0; private int daylight = 0; private int tSec = 0; private int factor = 0; private int second = theDate.getSeconds(); private int minute = theDate.getMinutes(); private int hour = theDate.getHours(); private int day = theDate.getDate(); private int month = theDate.getMonth() + 1; private int year = theDate.getYear(); private int this_tz_offset = theDate.getTimezoneOffset(); private String thePath = ""; private Thread timer = null; private ImageIcon theImage[] = new ImageIcon[14]; private int lastsec = 0; private int totalSec = 0; private int theTime = 0; private int days_in_month[][] = { {31,29,31,30,31,30,31,31,30,31,30,31}, {31,28,31,30,31,30,31,31,30,31,30,31}, {31,28,31,30,31,30,31,31,30,31,30,31}, {31,28,31,30,31,30,31,31,30,31,30,31}}; private int t_hrs, t_mins, t_secs, t_month, t_day, t_year ,t_daylight, tz_offset; private int s, rDays=0, rHours=0, rMinutes=0, rSecs=0; private int rYear=0, rMonth=0, rDay=0, rHour=0, rMinute=0, rSecond=0; private boolean tminus; private int days_in_year[] = {366,365,365,365}; private int x_loc=5, y_loc= 5; private int colon_space = 7; private int dead_space = 9; private int digit_space = 15; private int base_today = 0; private int base_target = 0; private String param = ""; public void init() { //.Get parameters from html tag.// try { saying = getParameter("text"); path = getParameter("path"); param = getParameter("dest"); font = getParameter("font"); try { dest = new URL (getDocumentBase(), param); } catch(MalformedURLException mal) { System.out.println("Malformed URL: Check Applet tag. "); } param = getParameter ("YEAR"); t_year = Integer.parseInt (param); param = getParameter ("MONTH"); t_month = Integer.parseInt (param); param = getParameter ("DAY"); t_day = Integer.parseInt (param); param = getParameter ("HOUR"); if (param != null) { t_hrs = Integer.parseInt (param); } else { t_hrs = 0; } param = getParameter ("MINUTE"); if (param != null) { t_mins = Integer.parseInt (param); } else { t_mins = 0; } param = getParameter ("SECOND"); if (param != null) { t_secs = Integer.parseInt (param); } else { t_secs = 0; } param = getParameter ("TIMEZONE"); if (param != null) tz_offset = Integer.parseInt (param); else tz_offset = 0; param = getParameter ("DAYLIGHT"); if (param != null) { t_daylight = Integer.parseInt (param); } else { t_daylight = 0; } } catch (Exception e) { return; } // Load the digit images.// for (int i = 0; i <= 9; i++) { theImage[i] = new ImageIcon(path + i + font + ".gif"); } //.Load the colon image.// theImage[10] = new ImageIcon(path + "c_" + font + ".gif"); //.Load the t-minus image.// theImage[11] = new ImageIcon(path + "tm_" + font + ".gif"); //.Load the t-plus image.// theImage[12] = new ImageIcon(path + "tp_" + font + ".gif"); //.Load the spacer image.// theImage[13] = new ImageIcon(path + "b_" + font + ".gif"); //.The array "days_in_month[]" is used to keep track of the # of days in a month.// //.It is also used to keep track of the leap year.// //.If the year is 1996 and the month is 2, then 1996 mod 4 = 0.// //.so days_in_month[0][2-1] = 29. 29 is used for the math.// //.The array "days_in_year[]" is used to keep track of the leap year.// //.If the year is 1996, then 1996 mod 4 = 0, and 366 would be used.// //.in the computation.// //.Leap years are evenly mod(ed).// //.Calculate number of seconds from 00:00:00 Jan 1, 1990 until target.// factor = 24 * 60 * 60; base_target += t_secs; base_target += t_mins * 60; base_target += t_hrs * 60 * 60; base_target += (t_day-1) * factor; for (i=1; i 0) theImage[12].paintIcon(this,g,x_loc,y_loc); //.Display status bar message on deadline.// if(totalSec == 0) showStatus(saying); //.Add a digit spacer.// x_loc+=digit_space; tSec = Math.abs(totalSec); rDays = (int) Math.floor (tSec / (24.0*60*60) ); rHours = (int) Math.floor((tSec % (24*60*60)) / 3600.0); rMinutes = (int) Math.floor( (tSec % 3600) /60.0); rSecs = tSec % 60; //.Show days digit.// theImage[rDays/1000].paintIcon(this,g,x_loc,y_loc); //.Add a digit spacer.// x_loc+=digit_space; //.Show days digit.// theImage[(rDays % 1000) / 100].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show days digit.// theImage[(rDays % 100) / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show days digit.// theImage[rDays % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show hours digit.// theImage[rHours / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show hours digit.// theImage[rHours % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show minutes digit.// theImage[rMinutes / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show minutes digit.// theImage[rMinutes % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show seconds digit.// theImage[rSecs / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show seconds digit.// theImage[rSecs % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; } //.Display countdown clock digits and current date & time clock under it.// public void paintDigClk(Graphics g) { totalSec++; //.Increment the counter.// //.Show counter value.// System.out.println("totalSec= " + totalSec); //.Center display within applet border.// x_loc=5; y_loc=4; //.Show blank image.// theImage[13].paintIcon(this,g,x_loc,y_loc); //.Add blank spacer.// x_loc+=digit_space; //.Show "T Minus" image before deadline.// if(totalSec < 0) theImage[11].paintIcon(this,g,x_loc,y_loc); //.Show "T Plus" image after deadline.// if(totalSec > 0) theImage[12].paintIcon(this,g,x_loc,y_loc); //.Display status bar message on deadline.// if(totalSec == 0) showStatus(saying); //.Add a digit spacer.// x_loc+=digit_space; tSec = Math.abs(totalSec); rDays = (int) Math.floor (tSec / (24.0*60*60) ); rHours = (int) Math.floor((tSec % (24*60*60)) / 3600.0); rMinutes = (int) Math.floor( (tSec % 3600) /60.0); rSecs = tSec % 60; //.Show days digit.// theImage[rDays/1000].paintIcon(this,g,x_loc,y_loc); //.Add a digit spacer.// x_loc+=digit_space; //.Show days digit.// theImage[(rDays % 1000) / 100].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show days digit.// theImage[(rDays % 100) / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show days digit.// theImage[rDays % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show hours digit.// theImage[rHours / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show hours digit.// theImage[rHours % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show minutes digit.// theImage[rMinutes / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show minutes digit.// theImage[rMinutes % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show seconds digit.// theImage[rSecs / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show seconds digit.// theImage[rSecs % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show blank image.// theImage[13].paintIcon(this,g,x_loc,y_loc); //.Add blank spacer.// x_loc+=digit_space; //.Show blank image.// theImage[13].paintIcon(this,g,x_loc,y_loc); //.Add blank spacer.// x_loc+=digit_space; //.-----------Current Date & Time display---------.// //.Get current date.// theDate = new Date(); //.Center display within applet border.// x_loc=5; y_loc=28; rYear = theDate.getYear() - 100; rMonth = theDate.getMonth(); rDay = theDate.getDate(); rHour = theDate.getHours(); rMinute = theDate.getMinutes(); rSecond = theDate.getSeconds(); //.Show month digit.// theImage[rMonth/10].paintIcon(this,g,x_loc,y_loc); //.Add a digit spacer.// x_loc+=digit_space; //.Show month digit.// theImage[rMonth%10].paintIcon(this,g,x_loc,y_loc); //.Add a digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show days digit.// theImage[rDay/10].paintIcon(this,g,x_loc,y_loc); //.Add a digit spacer.// x_loc+=digit_space; //.Show days digit.// theImage[rDay % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show year digit.// theImage[rYear / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show year digit.// theImage[rYear % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Add spacer to seperate date from time.// x_loc+=dead_space; //.Show hours digit.// theImage[rHour / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show hours digit.// theImage[rHour % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show minutes digit.// theImage[rMinute / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show minutes digit.// theImage[rMinute % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show seconds digit.// theImage[rSecond / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show seconds digit.// theImage[rSecond % 10].paintIcon(this,g,x_loc,y_loc); theDate = null; } //.Display time & date clock digits.// public void paintlocClk(Graphics g) { theDate = new Date(); //.Center display within applet border.// x_loc=5; y_loc=4; rYear = theDate.getYear() - 100; rMonth = theDate.getMonth(); rDay = theDate.getDate(); rHour = theDate.getHours(); rMinute = theDate.getMinutes(); rSecond = theDate.getSeconds(); System.out.println(rMonth + " " + rDay + " " + rYear); //.Show month digit.// theImage[rMonth/10].paintIcon(this,g,x_loc,y_loc); //.Add a digit spacer.// x_loc+=digit_space; //.Show month digit.// theImage[rMonth%10].paintIcon(this,g,x_loc,y_loc); //.Add a digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show days digit.// theImage[rDay/10].paintIcon(this,g,x_loc,y_loc); //.Add a digit spacer.// x_loc+=digit_space; //.Show days digit.// theImage[rDay % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show year digit.// theImage[rYear / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show year digit.// theImage[rYear % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Add digit spacer.// x_loc+=digit_space; //.Show hours digit.// theImage[rHour / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show hours digit.// theImage[rHour % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show minutes digit.// theImage[rMinute / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show minutes digit.// theImage[rMinute % 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show colon image.// theImage[10].paintIcon(this,g,x_loc,y_loc); //.Add colon spacer.// x_loc+=colon_space; //.Show seconds digit.// theImage[rSecond / 10].paintIcon(this,g,x_loc,y_loc); //.Add digit spacer.// x_loc+=digit_space; //.Show seconds digit.// theImage[rSecond % 10].paintIcon(this,g,x_loc,y_loc); theDate = null; } //.Start applet display.// public void start() { if(timer == null) { timer = new Thread(this); timer.start(); } } //.Shut down thread if closing applet.// public void stop() { timer = null; } //.Run applet from current thread.// public void run() { Thread me = Thread.currentThread(); while (timer == me) { try { Thread.currentThread().sleep(1000); } catch (InterruptedException e) { System.out.println("Interrupted Exception Error!"); } repaint(); //.Update the graphics by calling update method.// } } public void update(Graphics g) { paintCountDownTimer(g); } public boolean mouseEnter(Event evt, int x, int y) { System.out.println("Developed by: Michael Hartman"); System.out.println("hartmms@eng.auburn.edu"); return(true); } public boolean mouseUp(Event evt, int x, int y) { getAppletContext().showDocument(dest); return(true); } }