hi guys, i am trying to create a simple timer program. the problem is when i click on the start/stop button the program only moves one second then another when i click again. can anybody help please?{import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
public class Timer extends JFrame implements Runnable,ActionListener
{
public final JButton startStopButton= new JButton("Start/Stop");
//JLabel startStopButton= new JLabel();
private int secs;
private int mins;
private int hrs;
private Thread clock;
public void destroy()
{
clock.stop();
}
public void init()
{
if(clock == null)
{
clock = new Thread(this);
clock.start();
}
}
public void actionPerformed(ActionEvent ae)
{
++secs;
if(secs == 60)
{
mins++;
secs = 0;
}
if(mins == 60)
{
hrs++;
secs = 0;
mins = 0;
}
startStopButton.setText(" "+ hrs + ": " + mins + ":" + secs +"");
System.out.println(" "+ hrs + ": " + mins + ":" + secs +"");
}
public void run()
{
while(true)
{
repaint();
try
{
clock.sleep(1000);
}
catch(InterruptedException e)
{
}
}
}
public void start()
{
clock.resume();
}
public void stop()
{
clock.suspend();
}
public Timer ()
{
startStopButton.addActionListener(this);
setTitle(" "+ Calendar.getInstance().getTime());
getContentPane().add(startStopButton);
setSize(100,50);
setVisible(true);}
public static void main(String[] arg)
{
new Timer().addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
//}
}
}
}