Time refresh doesn't work .... probably flaws in the code. Please help ...

Making a time display and try to keep track of the system time every second. When I pruposely changed the system time for the first time, it worked; another time it wouldn't work and it stopped. Where is the bug please ...
tick_24 = new Timer ( 1000, new ActionListener () {
     public void actionPerformed ( ActionEvent ae ) {
          times = (GregorianCalendar) Calendar.getInstance ();
          int h = times.get(Calendar.HOUR_OF_DAY);
          int m = times.get(Calendar.MINUTE);
          int s = times.get(Calendar.SECOND);
          String time_now = configTime(h,m,s);
                // time_display is a JLabel;
          time_display.setText(time_now);
          times.add(Calendar.SECOND,1);
tick_24.start();

Can't help with the bug, but try this, you might get something out of it
import java.util.*;
import java.text.*;
import javax.swing.*;
import java.awt.*;
class TimeDisplay extends JFrame
  private static JLabel lbl = new JLabel();
  public static void main(String args[])
    new TimeDisplay();
  public TimeDisplay()
    super("Time Display");
    setSize(200,50);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    Container frame = getContentPane();
    JPanel jp = new JPanel(new FlowLayout());
    jp.add(lbl);
    frame.add(jp);
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((dim.width - frame.getWidth())/2, (dim.height - frame.getHeight())/2);
    setContentPane(frame);
    setVisible(true);
    startTheClock();
  private static void startTheClock()
    final java.util.Timer tmr = new java.util.Timer();
    tmr.scheduleAtFixedRate(new TimerTask()
      SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
      int ctr;
      public void run()
        Calendar cal = Calendar.getInstance();
        lbl.setText(sdf.format(cal.getTime()));
        ctr++;
        if(ctr==20) tmr.cancel();
    },0,1000);
}

Similar Messages

Maybe you are looking for

  • New Update to Edge Reflow CC Available!

    Today, we are pleased to announce that an update to Edge Reflow is now available. Included in this release are the following new features: Multi-page design: On the right side of Reflow's design surface (below the recently added 'Assets Panel' and ab

  • How to expose a file in XI 3.0?

    Hi friends, I have the requeriment to expose a wsdl file in SAP XI 3.0 SP 24. As everyone know this version hasn't a service registry. Also the client needs in the URL the clausule wsdl? . I was thinking to create a SICF service in order to response

  • Apple Pay - Card Design Not Reflected in Passbook

    I started using Apple Pay yesterday, and all of my cards loaded quickly and easily. However, the card designs on my Citi cards (I have 2), are not being reflected. When loaded into Apple Pay, they are just generic looking cards, not the actual design

  • Action listener in different class

    Hi I now have a class called Gui and a class called Listener. The gui contains public class Gui implements ActionListener public void actionPerformed(ActionEvent e) { }the Listener contains public class Listener extends gui implements ActionListener

  • What Are The Limits To Aperture? (Masters, Versions, Projects...)

    If Apple has a specification for any of these, I couldn't find it. It's obviously not on the Aperture web site under tech specs. I couldn't find it in the user manual, but I have been known to stink at searching the manual. I did some searching on th