Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4150578

The initial delay before the first "ringing" of the Timer too much

    XMLWordPrintable

Details

    • sparc
    • solaris_2.5.1

    Description



      Name: akC57697 Date: 06/19/98



       The initial delay before the first "ringing" of the Timer essentially
      more then getInitialDelay().
       
      The doc says:
      "
      public Timer(int delay,
                   ActionListener listener)

           Creates a Timer that will notify its listeners every delay milliseconds.
           Parameters:
               delay - The number of milliseconds between listener notification
               listener - An initial listener
               
      public void setInitialDelay(int initialDelay)

           Sets the Timer's initial delay. This will be used for the first
           "ringing" of the Timer only. Subsequent ringings will be
           spaced using the delay property.
      "
       
      The example:
      ------------------------------8-<--------------------------------------------
      import com.sun.java.swing.Timer;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;
      import java.util.Date;

      public class Test {
        public static void main(String[] argv) {

          TestActionListener l=new TestActionListener();
          
          Timer c=new Timer(100,l);
       
          c.setRepeats(false);
          
          System.out.println("The initial delay :"+c.getInitialDelay());
          System.out.println("Start :"+new Date(System.currentTimeMillis()));

          c.start(); // start timer

          try {
            Thread.sleep(10000); // wait
          } catch(InterruptedException e) {}
          System.out.println("Finish :"+new Date(System.currentTimeMillis()));
        }
      }

          class TestActionListener implements ActionListener {
            public void actionPerformed(ActionEvent e) {
              System.out.println("Done at:"+
                                   new Date(System.currentTimeMillis()));
            }
          }
      ---------------------------->-8----------------------------------------------
      Output:
      java Test
      The initial delay :100
      Start :Fri Jun 19 13:58:21 GMT+04:00 1998
      Done at:Fri Jun 19 13:58:26 GMT+04:00 1998
      Finish :Fri Jun 19 13:58:32 GMT+04:00 1998

      java full version "JDK-1.2beta4-J"

      ======================================================================

      Attachments

        Activity

          People

            rkarsunw Ralph Kar (Inactive)
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: