Thursday, December 14, 2017

Set up a Timer to repeatedly execute a piece of code or a task or to repeatedly update the state of your objects


Lets say, you have an integer field and you want to increment it by 5 every minute.

public class TimerTest {
      private int theValue = 0;
      private javax.swing.Timer timer1 = null;

      public TimerTest() {
            //Set up the timer to perform the action repeatedly
             //after a delay of 1 minute which is 60000 milliseconds.
            timer1 = new javax.swing.Timer(60000, new TimerAction());
            timer1.start();

      }

      private class TimerAction implements ActionListener {
            @Override
            public void actionPerformed(ActionEvent e) {
                  theValue += 5;
                  System.out.println("The value currently is "+theValue);
            }
      }
}

---------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment