swing - Java Logarithm Clock Gives Innacurate Answers -
ok, building clock give out times in form of log10(hour) , minute , second in same format, keep getting strange outputs when runs. nans , infinity(or negative). have feeling wrong numbers using(like maybe large or that) note: currenttime long, calendar calendar, , hour, minute, , second doubles. clock variable jlabel. after program goes through 2 iterations switches on nans.
this.timer.scheduleatfixedrate(new timertask() { @override public void run() { new swingworker<void, void>() { @override protected void doinbackground() throws exception { currenttime = system.currenttimemillis(); calendar.settime(new date(currenttime)); hour = math.log10(hour); minute = math.log10(minute); second = math.log10(second); system.out.println(hour + " " + minute + " " + second); return null; } @override protected void done() { clock.settext("<html><body><p>log time: " + "log<sub>10</sub>(" + hour + ") || " + "log<sub>10</sub>(" + minute + ") || " + "log<sub>10</sub>(" + second + ")</p></body></html>"); } }.execute(); } }, 0, 200);
this code doesn't make lot of sense:
currenttime = system.currenttimemillis(); calendar.settime(new date(currenttime)); hour = math.log10(hour); minute = math.log10(minute); second = math.log10(second);
you're setting time in calendar
- ignoring it. expect you'd want like:
currenttime = system.currenttimemillis(); calendar.settime(new date(currenttime)); hour = math.log10(calendar.get(calendar.hour_of_day)); minute = math.log10(calendar.get(calendar.minute)); second = math.log10(calendar.get(calendar.second));
edit: noted on comments, need consider you'll when hour, minute or second 0. (it's unclear why you'd want use log-based clock start with, honest.)
Comments
Post a Comment