Clock3.java

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Clock3 
{
   NTJFrame frame = new NTJFrame("Clock");
   Drawing drawing = new Drawing();
   TimeKeeper time = new TimeKeeper();
   int hours=0, minutes=0, seconds=0;
   boolean stopped = false;
   
   public Clock3()
   {
      frame.getContentPane().add(drawing,"Center");
      frame.setVisible(true);
      frame.addMouseListener(new MouseListen());
      time.start();
   }
   
   public static void main (String[] args)
   {
      new Clock3();
   }
   
   class MouseListen extends MouseAdapter
   {
      public void mouseReleased(MouseEvent e)
      {
         if (e.isPopupTrigger())
            stopped = !stopped;
      }
   }
   
   class Drawing extends JComponent
   {
      public Drawing()
      {
         repaint();
      }
      
      public void paint(Graphics g)
      {
         g.drawString(hours + ":" + minutes + ":" + seconds, 100,100);
      }
   }
   
   class TimeKeeper extends Thread
   {
      public void run()
      {
         try
         {
            while (true)
            {
               sleep(1000);
               if (!stopped)
               {
                  seconds++;
                  if (seconds > 59)
                  {
                     seconds = 0;
                     minutes++;
                     if (minutes > 59)
                     {
                        minutes = 0;
                        hours++;
                     }
                  }
                  drawing.repaint();
               }
            }
         }
         catch (InterruptedException e)
         {
         }
      }
   }
}