So essentially I have a timer that has four timers.
*Overall Timer
*Running Timer
*Down Timer
*Break Timer
As soon as the start button is clicked it starts tracking the overall timer as well as starting the running timer. When any component is shut off or the machine is shut down, the down timer kicks in and starts accumulating, the running timer shuts stops accumulating, and the overall timer continues.
I think I'm at the verge of making this very convoluted. I was trying to create a simple mathematical expression that would allow me to just pull the remaining time given from when the Overall timer started minus whichever appropriate variables applied. So to get the running timer would be:
System.CurrentTimemillis() - overallTimer - downTimer - breakTimer;
I guess what I'm hoping for is some advice and maybe direction on an appropriate, somewhat more organized approach.
I was thinking of making an array in order to store the different timers so I could just tack onto them and then return the array indice that applied.
Like I said, I feel like I'm making this much more complex than it needs to be and my mind is running a mile a minute.
Hopefully this was enough information to create a clear picture of where I'm headed with this. Thanks in advance for the advice.
*Overall Timer
*Running Timer
*Down Timer
*Break Timer
As soon as the start button is clicked it starts tracking the overall timer as well as starting the running timer. When any component is shut off or the machine is shut down, the down timer kicks in and starts accumulating, the running timer shuts stops accumulating, and the overall timer continues.
I think I'm at the verge of making this very convoluted. I was trying to create a simple mathematical expression that would allow me to just pull the remaining time given from when the Overall timer started minus whichever appropriate variables applied. So to get the running timer would be:
System.CurrentTimemillis() - overallTimer - downTimer - breakTimer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package my.ppgdowntimerecorder;
/**
*
* @author Michael McNichol
*/
public class timer
{
long initializedTime = 0;
long runningTime = 0;
long downTime = 0;
long breakTime = 0;
public void setCurrentTime()
{
initializedTime = System.currentTimeMillis();
}
public void setRunningTime()
{
runningTime = System.currentTimeMillis();
}
public void setDownTime()
{
downTime = System.currentTimeMillis();
}
public long getInitialTime()
{
return initializedTime;
}
public long getRunningTime()
{
return initializedTime - downTime - breakTime;
}
public long getDownTime()
{
return downTime;
}
public long getBreakTime()
{
return breakTime;
}
public String getTime(long timeBase) //This returns Overall Time
{
long timeReturned = System.currentTimeMillis() - timeBase;
timeReturned = timeReturned / 1000;
String seconds = Integer.toString((int)(timeReturned % 60));
String minutes = Integer.toString((int)((timeReturned % 3600) / 60));
String hours = Integer.toString((int)(timeReturned / 3600));
if (seconds.length() < 2)
seconds = "0" + seconds;
if (minutes.length() < 2)
minutes = "0" + minutes;
if (hours.length() < 2)
hours = "0" + hours;
return hours + ":" + minutes + ":" + seconds;
}
public String getTime(long timeBase, long timeVarOne, long timeVarTwo) //This returns downTime, breakTime, or runningTime
{ //depending on how the values are passed.
long timeReturned = System.currentTimeMillis() - timeBase - timeVarOne - timeVarTwo;
timeReturned = timeReturned / 1000;
String seconds = Integer.toString((int)(timeReturned % 60));
String minutes = Integer.toString((int)((timeReturned % 3600) / 60));
String hours = Integer.toString((int)(timeReturned / 3600));
if (seconds.length() < 2)
seconds = "0" + seconds;
if (minutes.length() < 2)
minutes = "0" + minutes;
if (hours.length() < 2)
hours = "0" + hours;
return hours + ":" + minutes + ":" + seconds;
}
}
I guess what I'm hoping for is some advice and maybe direction on an appropriate, somewhat more organized approach.
I was thinking of making an array in order to store the different timers so I could just tack onto them and then return the array indice that applied.
Like I said, I feel like I'm making this much more complex than it needs to be and my mind is running a mile a minute.
Hopefully this was enough information to create a clear picture of where I'm headed with this. Thanks in advance for the advice.