AdamTheNoob
YaBB Newbies
Offline
Posts: 46
Re: constructor undefined; new to OOP
Reply #2 - Feb 11th , 2010, 8:30am
Ahhh, much better. Thanks a ton! Corrected code: PFont fontA; CountupTimer CountupTimer1 = new CountupTimer(millis(),true,false); void setup() { size(1280, 720); fontA = loadFont("HelveticaNeue-Bold-48.vlw"); textFont(fontA, 32); // Set the font and its size (in units of pixels) } void draw() { background(0); //DISPLAY TIMER textAlign(CENTER); text(CountupTimer1.display(), width/2, height-10); } class CountupTimer { int milliseconds; int seconds; int minutes; int hours; int days; String displayTime; boolean showMinutes; boolean showHours; int timerStart; // Arguments: Timer Start in Millis; show minutes True/False; show hours true/false CountupTimer(int tempStart, boolean tempMinutes, boolean tempHours) { timerStart = tempStart; showMinutes = tempMinutes; showHours = tempHours; } String display() { // calculate elapsed time in days, hours, minutes, seconds, and milliseconds milliseconds = millis() - timerStart; seconds = milliseconds / 1000; minutes = seconds / 60; hours = minutes / 60; days = hours / 24; // Now we need to subtract elapsed minutes from seconds, hours from minutes, etc, // so that we don't end up with silly things like "01:65:3912:39123421" milliseconds -= seconds * 1000; seconds -= minutes * 60; minutes -= hours * 60; hours -= days * 24; // Lets set up our string before we actually print it: if(showMinutes && showHours) displayTime = nf(hours,2,0)+":"+nf(minutes,2,0)+":"; else if(showMinutes) displayTime = nf(minutes,2,0)+":"; displayTime += nf(seconds,2,0)+":"+nf(milliseconds,3,0); return displayTime; } }