Results 1 to 3 of 3
  1. #1
    chyeeqi is offline Member
    Join Date
    Aug 2009
    Posts
    23
    Rep Power
    0

    Default how can i make a clock which can auto update every second

    i create a clock, but the time cannot updated. how can i make it auto update every seconds???

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Use a Timer. Either java.util.Timer or if this is a Swing application, javax.swing.Timer.

    db

  3. #3
    OmerHalit is offline Member
    Join Date
    Mar 2010
    Posts
    41
    Rep Power
    0

    Default

    Java Code:
    import javax.swing.Timer;
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
      
          TimeTimer = new Timer(1000, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.print(getDateTime());
                }
            });
            TimeTimer.setRepeats(true);
            TimeTimer.start();
    
        private String getDateTime() {
            DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
            Date date = new Date();
            return dateFormat.format(date);
        }
    ;)

Similar Threads

  1. 24 hour clock to 12 hour clock project.
    By bs3ac in forum New To Java
    Replies: 4
    Last Post: 01-08-2013, 10:10 AM
  2. Auto contrast and auto brightness
    By oxxxis in forum Java 2D
    Replies: 0
    Last Post: 01-21-2010, 08:32 PM
  3. clock
    By ws6driver in forum New To Java
    Replies: 1
    Last Post: 07-31-2009, 04:15 AM
  4. Auto-complete/Auto-fix for custom statement
    By dark_cybernetics in forum Eclipse
    Replies: 0
    Last Post: 08-19-2008, 11:19 AM
  5. Auto Update Function
    By abiieez in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 04:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •