import java.applet.Applet; import java.awt.*; import java.util.StringTokenizer; /** * 記念日までのカウント・ダウン、記念日からのカウント・アップを千分の一秒までカウントするアプレット * @author せぎてつ * @version 1.0 */ public class CountDownUpInMillis extends CountDownUp { protected static final int HMSMS = 4, DAYS_AND_HMSMS = 5; protected Image secondImage; /* factory method */ protected CalcTimeDifference createCalcTimeDifference() { return new CalcTimeDiffInMillisJDK11(); } protected void setDisplayStyleParameter() { String s = getParameter("displayStyle"); if (s == null) { displayStyle = HMS; } else if (s.equalsIgnoreCase("DAYS")) { displayStyle = DAYS; } else if (s.equalsIgnoreCase("HMS")) { displayStyle = HMS; } else if (s.equalsIgnoreCase("DAYS_AND_HMS")) { displayStyle = DAYS_AND_HMS; } else if (s.equalsIgnoreCase("HMSMS")) { displayStyle = HMSMS; } else if (s.equalsIgnoreCase("DAYS_AND_HMSMS")) { displayStyle = DAYS_AND_HMSMS; } } protected void setImageParameters() { tracker = new MediaTracker(this); imageDir = getParameter("imageDir"); for (int i = 0; i < 10; i++) { digits[i] = getImage(getDocumentBase(), imageDir + i + ".gif"); tracker.addImage(digits[i], 0); } if (displayStyle == HMS || displayStyle == DAYS_AND_HMS || displayStyle == HMSMS || displayStyle == DAYS_AND_HMSMS) { hourImage = setImage("hourImage"); minuteImage = setImage("minuteImage"); } if (displayStyle == DAYS_AND_HMS || displayStyle == DAYS_AND_HMSMS) { middleImage = setImage("middleImage"); } if (displayStyle == HMSMS || displayStyle == DAYS_AND_HMSMS) { secondImage = setImage("secondImage"); } beforeFrontImage = setImage("beforeFrontImage"); beforeEndImage = setImage("beforeEndImage"); afterFrontImage = setImage("afterFrontImage"); afterEndImage = setImage("afterEndImage"); } protected void paintDaysAndHMS() { if (displayStyle == DAYS) { paintDiffDays(); } else if (displayStyle == HMS) { int num = timeDifference.getDiffDays(); num = num * 24 + timeDifference.getDiffHours(); paintDiffHMS(num, timeDifference.getDiffMinutes(), timeDifference.getDiffSeconds()); } else if (displayStyle == DAYS_AND_HMS) { paintDiffDays(); paintImage(middleImage); paintDiffHMS(timeDifference.getDiffHours(), timeDifference.getDiffMinutes(), timeDifference.getDiffSeconds()); } else if (displayStyle == HMSMS) { int num = timeDifference.getDiffDays(); num = num * 24 + timeDifference.getDiffHours(); paintDiffHMSMS(num, timeDifference.getDiffMinutes(), timeDifference.getDiffSeconds(), ((CalcTimeDiffInMillisJDK11)timeDifference).getDiffMilliSeconds()); } else if (displayStyle == DAYS_AND_HMSMS) { paintDiffDays(); paintImage(middleImage); paintDiffHMSMS(timeDifference.getDiffHours(), timeDifference.getDiffMinutes(), timeDifference.getDiffSeconds(), ((CalcTimeDiffInMillisJDK11)timeDifference).getDiffMilliSeconds()); } } protected void paintDiffHMSMS(int diffHours, int diffMinutes, int diffSeconds, int diffMilliSeconds) { paintDiffHMS(diffHours, diffMinutes, diffSeconds); paintImage(secondImage); paintImage(digits[diffMilliSeconds / 100]); paintImage(digits[(diffMilliSeconds % 100) / 10]); } protected void setCurrentTime() { if (displayStyle == DAYS || displayStyle == HMS || displayStyle == DAYS_AND_HMS) { ((CalcTimeDiffInMillisJDK11)timeDifference).setCurrentTime(true); } else if (displayStyle == HMSMS || displayStyle == DAYS_AND_HMSMS) { ((CalcTimeDiffInMillisJDK11)timeDifference).setCurrentTime(false); } } }