import java.awt.*;
 import java.awt.event.*;
 import java.awt.geom.*;
 import javax.swing.*;
 import java.net.*;
 import java.io.*;
 import java.awt.Graphics;
 import java.util.*;
 import java.text.*;
 import java.util.Locale;

 class chronometerThread extends Thread
 {
 public long i;
 JFrame a;
 public boolean done;
 public chronometerThread(JFrame ai)
 {a=ai;i=0;done=true;}
  
 public void reset() {i=0;}

 
 public void run()
 {
 while(done)
 {
 a.validate();
 a.repaint();
 try {Thread.sleep(10);i++;}
 catch(InterruptedException e)
 {System.err.println(e.toString());}
 }
 }
 }

 public class chronometerP extends JPanel implements Serializable,ActionListener
 {
 private static final long serialVersionUID=358044808532797990L;
 JTextField jb;
 JButton b;
  Font F;
 chronometerThread r;
 int minute;
 int  second;
 int  centisecond;
 JPanel jp;
 JFrame jf;
 
 public chronometerP(JFrame bi)
 {
 jf=bi;	
 jp=new JPanel();
 jp.setLayout(new BorderLayout());
 second=0;
 jb=new JTextField("");
 b=new JButton("start/stop");
 b.addActionListener(this);
 F=new Font("TimesRoman",Font.BOLD,24);
 jb.setFont(F);
 b.setFont(F);
 r=new chronometerThread(jf);
 jp.add(jb,BorderLayout.NORTH);
 jp.add(b,BorderLayout.SOUTH);
 jf.add(jp,BorderLayout.CENTER);
 }
 
public void actionPerformed( ActionEvent e)
{
if(r.i==0) r.start();
else {r.done=false;r=new chronometerThread(jf);
}
}

public void paintComponent(Graphics g)
{    minute=(int)(r.i/6000);
     second=(int)(r.i/100%60);
     centisecond=(int)(r.i%100);
     jb.setText(""+minute+" "+second+"  "+centisecond);
}

}
