Rravi
Rravi

Reputation: 21

My DigitalClock not working

I made a digital clock. but its not working properly.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
public class DigitalClock extends JFrame implements ActionListener {
  JLabel  l1 = new JLabel();
  Timer  t;
  public  DigitalClock() {
     super("Digital Clock");
     l1.setFont( new Font("Verdana",Font.BOLD,11) );
     l1.setHorizontalAlignment( JLabel.RIGHT);
     l1.setVerticalAlignment( JLabel.BOTTOM);
     t = new Timer(1000,this);
     getContentPane().add(l1);
     setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     setSize(110,100);
     setVisible(true);
     // call actionPerformed to get Time at the startup
     actionPerformed(null);
  }
  public void actionPerformed(ActionEvent evt)  {
      l1.setText( new Date().toString().substring(11,19));
  }
  public static void main(String args[]) {
     new DigitalClock();
  }
} // end of class

I made a digital clock. but its not working properly.
Help me i can't find the problem..
plz help.. output is constant time

Upvotes: 0

Views: 101

Answers (2)

gifpif
gifpif

Reputation: 4917

After creating Time obj just start timer t.start();

Upvotes: 3

camickr
camickr

Reputation: 324128

in output time is constant not move. but i want continues time clock

Did you start the Timer?

If you start the Timer then you don't even need:

// actionPerformed(null);

Upvotes: 2

Related Questions