Hello,
I'm having trouble displaying an output from my code. It suppose to act like a stopwatch where seconds increment and then minutes and then hours but for some reason its not working and I cannot figure out why... :-( hope some some can guide me.
Thanks
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package stopwatch;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
/**
*
* @author Taimoor
*/
public class stopWatch
{
int seconds = 0;
int minutes = 0;
int hours = 0;
boolean t = true;
Timer timer;
public stopWatch()
{
timer = new Timer(1000,new TimerClass());
timer.start();
while(t)
{
System.out.print(seconds + minutes + hours);
}
}
class TimerClass implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
seconds+= 1;
if (seconds > 59)
{
seconds = 0;
minutes += 1;
}
if (minutes > 59)
{
minutes = 0;
hours += 1;
}
if(hours > 23)
{
hours = 0;
}
}
}
public static void main(String[]args)
{
stopWatch watch = new stopWatch();
}
}