<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSwing_JFC%2FTimer</id>
		<title>Java/Swing JFC/Timer - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSwing_JFC%2FTimer"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Swing_JFC/Timer&amp;action=history"/>
		<updated>2026-05-17T06:40:27Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Swing_JFC/Timer&amp;diff=7389&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Swing_JFC/Timer&amp;diff=7389&amp;oldid=prev"/>
				<updated>2010-06-01T06:42:05Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:42, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Swing_JFC/Timer&amp;diff=7388&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Swing_JFC/Timer&amp;diff=7388&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:44Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== An applet that counts down from a specified time ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2004 David Flanagan.  All rights reserved.&lt;br /&gt;
 * This code is from the book Java Examples in a Nutshell, 3nd Edition.&lt;br /&gt;
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.&lt;br /&gt;
 * You may study, use, and modify it for any non-commercial purpose,&lt;br /&gt;
 * including teaching and use in open-source projects.&lt;br /&gt;
 * You may distribute it non-commercially as long as you retain this notice.&lt;br /&gt;
 * For a commercial use license, or to purchase the book, &lt;br /&gt;
 * please visit http://www.davidflanagan.ru/javaexamples3.&lt;br /&gt;
 */&lt;br /&gt;
import java.applet.AudioClip;&lt;br /&gt;
import java.awt.BorderLayout;&lt;br /&gt;
import java.awt.Color;&lt;br /&gt;
import java.awt.Font;&lt;br /&gt;
import java.awt.Image;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import java.awt.event.MouseEvent;&lt;br /&gt;
import java.awt.event.MouseListener;&lt;br /&gt;
import java.net.MalformedURLException;&lt;br /&gt;
import java.net.URL;&lt;br /&gt;
import java.text.NumberFormat;&lt;br /&gt;
import javax.swing.ImageIcon;&lt;br /&gt;
import javax.swing.JApplet;&lt;br /&gt;
import javax.swing.JLabel;&lt;br /&gt;
import javax.swing.SwingConstants;&lt;br /&gt;
import javax.swing.Timer;&lt;br /&gt;
/**&lt;br /&gt;
 * An applet that counts down from a specified time. When it reaches 00:00, it&lt;br /&gt;
 * optionally plays a sound and optionally moves the browser to a new page.&lt;br /&gt;
 * Place the mouse over the applet to pause the count; move it off to resume.&lt;br /&gt;
 * This class demonstrates most applet methods and features.&lt;br /&gt;
 */&lt;br /&gt;
public class Countdown extends JApplet implements ActionListener, MouseListener {&lt;br /&gt;
  long remaining; // How many milliseconds remain in the countdown.&lt;br /&gt;
  long lastUpdate; // When count was last updated&lt;br /&gt;
  JLabel label; // Displays the count&lt;br /&gt;
  Timer timer; // Updates the count every second&lt;br /&gt;
  NumberFormat format; // Format minutes:seconds with leading zeros&lt;br /&gt;
  Image image; // Image to display along with the time&lt;br /&gt;
  AudioClip sound; // Sound to play when we reach 00:00&lt;br /&gt;
  // Called when the applet is first loaded&lt;br /&gt;
  public void init() {&lt;br /&gt;
    // Figure out how long to count for by reading the &amp;quot;minutes&amp;quot; parameter&lt;br /&gt;
    // defined in a &amp;lt;param&amp;gt; tag inside the &amp;lt;applet&amp;gt; tag. Convert to ms.&lt;br /&gt;
    String minutes = getParameter(&amp;quot;minutes&amp;quot;);&lt;br /&gt;
    if (minutes != null)&lt;br /&gt;
      remaining = Integer.parseInt(minutes) * 60000;&lt;br /&gt;
    else&lt;br /&gt;
      remaining = 600000; // 10 minutes by default&lt;br /&gt;
    // Create a JLabel to display remaining time, and set some properties.&lt;br /&gt;
    label = new JLabel();&lt;br /&gt;
    label.setHorizontalAlignment(SwingConstants.CENTER);&lt;br /&gt;
    label.setOpaque(true); // So label draws the background color&lt;br /&gt;
    // Read some parameters for this JLabel object&lt;br /&gt;
    String font = getParameter(&amp;quot;font&amp;quot;);&lt;br /&gt;
    String foreground = getParameter(&amp;quot;foreground&amp;quot;);&lt;br /&gt;
    String background = getParameter(&amp;quot;background&amp;quot;);&lt;br /&gt;
    String imageURL = getParameter(&amp;quot;image&amp;quot;);&lt;br /&gt;
    // Set label properties based on those parameters&lt;br /&gt;
    if (font != null)&lt;br /&gt;
      label.setFont(Font.decode(font));&lt;br /&gt;
    if (foreground != null)&lt;br /&gt;
      label.setForeground(Color.decode(foreground));&lt;br /&gt;
    if (background != null)&lt;br /&gt;
      label.setBackground(Color.decode(background));&lt;br /&gt;
    if (imageURL != null) {&lt;br /&gt;
      // Load the image, and save it so we can release it later&lt;br /&gt;
      image = getImage(getDocumentBase(), imageURL);&lt;br /&gt;
      // Now display the image in the JLabel.&lt;br /&gt;
      label.setIcon(new ImageIcon(image));&lt;br /&gt;
    }&lt;br /&gt;
    // Now add the label to the applet. Like JFrame and JDialog, JApplet&lt;br /&gt;
    // has a content pane that you add children to&lt;br /&gt;
    getContentPane().add(label, BorderLayout.CENTER);&lt;br /&gt;
    // Get an optional AudioClip to play when the count expires&lt;br /&gt;
    String soundURL = getParameter(&amp;quot;sound&amp;quot;);&lt;br /&gt;
    if (soundURL != null)&lt;br /&gt;
      sound = getAudioClip(getDocumentBase(), soundURL);&lt;br /&gt;
    // Obtain a NumberFormat object to convert number of minutes and&lt;br /&gt;
    // seconds to strings. Set it up to produce a leading 0 if necessary&lt;br /&gt;
    format = NumberFormat.getNumberInstance();&lt;br /&gt;
    format.setMinimumIntegerDigits(2); // pad with 0 if necessary&lt;br /&gt;
    // Specify a MouseListener to handle mouse events in the applet.&lt;br /&gt;
    // Note that the applet implements this interface itself&lt;br /&gt;
    addMouseListener(this);&lt;br /&gt;
    // Create a timer to call the actionPerformed() method immediately,&lt;br /&gt;
    // and then every 1000 milliseconds. Note we don&amp;quot;t start the timer yet.&lt;br /&gt;
    timer = new Timer(1000, this);&lt;br /&gt;
    timer.setInitialDelay(0); // First timer is immediate.&lt;br /&gt;
  }&lt;br /&gt;
  // Free up any resources we hold; called when the applet is done&lt;br /&gt;
  public void destroy() {&lt;br /&gt;
    if (image != null)&lt;br /&gt;
      image.flush();&lt;br /&gt;
  }&lt;br /&gt;
  // The browser calls this to start the applet running&lt;br /&gt;
  // The resume() method is defined below.&lt;br /&gt;
  public void start() {&lt;br /&gt;
    resume();&lt;br /&gt;
  } // Start displaying updates&lt;br /&gt;
  // The browser calls this to stop the applet. It may be restarted later.&lt;br /&gt;
  // The pause() method is defined below&lt;br /&gt;
  public void stop() {&lt;br /&gt;
    pause();&lt;br /&gt;
  } // Stop displaying updates&lt;br /&gt;
  // Return information about the applet&lt;br /&gt;
  public String getAppletInfo() {&lt;br /&gt;
    return &amp;quot;Countdown applet Copyright (c) 2003 by David Flanagan&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  // Return information about the applet parameters&lt;br /&gt;
  public String[][] getParameterInfo() {&lt;br /&gt;
    return parameterInfo;&lt;br /&gt;
  }&lt;br /&gt;
  // This is the parameter information. One array of strings for each&lt;br /&gt;
  // parameter. The elements are parameter name, type, and description.&lt;br /&gt;
  static String[][] parameterInfo = {&lt;br /&gt;
      { &amp;quot;minutes&amp;quot;, &amp;quot;number&amp;quot;, &amp;quot;time, in minutes, to countdown from&amp;quot; },&lt;br /&gt;
      { &amp;quot;font&amp;quot;, &amp;quot;font&amp;quot;, &amp;quot;optional font for the time display&amp;quot; },&lt;br /&gt;
      { &amp;quot;foreground&amp;quot;, &amp;quot;color&amp;quot;, &amp;quot;optional foreground color for the time&amp;quot; },&lt;br /&gt;
      { &amp;quot;background&amp;quot;, &amp;quot;color&amp;quot;, &amp;quot;optional background color&amp;quot; },&lt;br /&gt;
      { &amp;quot;image&amp;quot;, &amp;quot;image URL&amp;quot;, &amp;quot;optional image to display next to countdown&amp;quot; },&lt;br /&gt;
      { &amp;quot;sound&amp;quot;, &amp;quot;sound URL&amp;quot;, &amp;quot;optional sound to play when we reach 00:00&amp;quot; },&lt;br /&gt;
      { &amp;quot;newpage&amp;quot;, &amp;quot;document URL&amp;quot;, &amp;quot;URL to load when timer expires&amp;quot; }, };&lt;br /&gt;
  // Start or resume the countdown&lt;br /&gt;
  void resume() {&lt;br /&gt;
    // Restore the time we&amp;quot;re counting down from and restart the timer.&lt;br /&gt;
    lastUpdate = System.currentTimeMillis();&lt;br /&gt;
    timer.start(); // Start the timer&lt;br /&gt;
  }&lt;br /&gt;
  // Pause the countdown&lt;br /&gt;
  void pause() {&lt;br /&gt;
    // Subtract elapsed time from the remaining time and stop timing&lt;br /&gt;
    long now = System.currentTimeMillis();&lt;br /&gt;
    remaining -= (now - lastUpdate);&lt;br /&gt;
    timer.stop(); // Stop the timer&lt;br /&gt;
  }&lt;br /&gt;
  // Update the displayed time. This method is called from actionPerformed()&lt;br /&gt;
  // which is itself invoked by the timer.&lt;br /&gt;
  void updateDisplay() {&lt;br /&gt;
    long now = System.currentTimeMillis(); // current time in ms&lt;br /&gt;
    long elapsed = now - lastUpdate; // ms elapsed since last update&lt;br /&gt;
    remaining -= elapsed; // adjust remaining time&lt;br /&gt;
    lastUpdate = now; // remember this update time&lt;br /&gt;
    // Convert remaining milliseconds to mm:ss format and display&lt;br /&gt;
    if (remaining &amp;lt; 0)&lt;br /&gt;
      remaining = 0;&lt;br /&gt;
    int minutes = (int) (remaining / 60000);&lt;br /&gt;
    int seconds = (int) ((remaining % 60000) / 1000);&lt;br /&gt;
    label.setText(format.format(minutes) + &amp;quot;:&amp;quot; + format.format(seconds));&lt;br /&gt;
    // If we&amp;quot;ve completed the countdown beep and display new page&lt;br /&gt;
    if (remaining == 0) {&lt;br /&gt;
      // Stop updating now.&lt;br /&gt;
      timer.stop();&lt;br /&gt;
      // If we have an alarm sound clip, play it now.&lt;br /&gt;
      if (sound != null)&lt;br /&gt;
        sound.play();&lt;br /&gt;
      // If there is a newpage URL specified, make the browser&lt;br /&gt;
      // load that page now.&lt;br /&gt;
      String newpage = getParameter(&amp;quot;newpage&amp;quot;);&lt;br /&gt;
      if (newpage != null) {&lt;br /&gt;
        try {&lt;br /&gt;
          URL url = new URL(getDocumentBase(), newpage);&lt;br /&gt;
          getAppletContext().showDocument(url);&lt;br /&gt;
        } catch (MalformedURLException ex) {&lt;br /&gt;
          showStatus(ex.toString());&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  // This method implements the ActionListener interface.&lt;br /&gt;
  // It is invoked once a second by the Timer object&lt;br /&gt;
  // and updates the JLabel to display minutes and seconds remaining.&lt;br /&gt;
  public void actionPerformed(ActionEvent e) {&lt;br /&gt;
    updateDisplay();&lt;br /&gt;
  }&lt;br /&gt;
  // The methods below implement the MouseListener interface. We use&lt;br /&gt;
  // two of them to pause the countdown when the mouse hovers over the timer.&lt;br /&gt;
  // Note that we also display a message in the statusline&lt;br /&gt;
  public void mouseEntered(MouseEvent e) {&lt;br /&gt;
    pause(); // pause countdown&lt;br /&gt;
    showStatus(&amp;quot;Paused&amp;quot;); // display statusline message&lt;br /&gt;
  }&lt;br /&gt;
  public void mouseExited(MouseEvent e) {&lt;br /&gt;
    resume(); // resume countdown&lt;br /&gt;
    showStatus(&amp;quot;&amp;quot;); // clear statusline&lt;br /&gt;
  }&lt;br /&gt;
  // These MouseListener methods are unused.&lt;br /&gt;
  public void mouseClicked(MouseEvent e) {&lt;br /&gt;
  }&lt;br /&gt;
  public void mousePressed(MouseEvent e) {&lt;br /&gt;
  }&lt;br /&gt;
  public void mouseReleased(MouseEvent e) {&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Swing Timer Demo ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import javax.swing.Timer;&lt;br /&gt;
/*&lt;br /&gt;
 * SwingTimerDemo.java&lt;br /&gt;
 *&lt;br /&gt;
 * Created on May 2, 2007, 3:25 PM&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 2007, Sun Microsystems, Inc&lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   * Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *   * Redistributions in binary form must reproduce the above&lt;br /&gt;
 *     copyright notice, this list of conditions and the following&lt;br /&gt;
 *     disclaimer in the documentation and/or other materials provided&lt;br /&gt;
 *     with the distribution.&lt;br /&gt;
 *   * Neither the name of the TimingFramework project nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT&lt;br /&gt;
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&lt;br /&gt;
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,&lt;br /&gt;
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY&lt;br /&gt;
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT&lt;br /&gt;
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE&lt;br /&gt;
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 *&lt;br /&gt;
 * @author Chet&lt;br /&gt;
 */&lt;br /&gt;
public class SwingTimerDemo implements ActionListener {&lt;br /&gt;
    &lt;br /&gt;
    private static long prevTime = 0;&lt;br /&gt;
    private static long startTime = 0;&lt;br /&gt;
    private static final int DELAY = 100;&lt;br /&gt;
    private static final int DURATION = 5 * DELAY;&lt;br /&gt;
    private static final int PROCESSING_TIME = 30;&lt;br /&gt;
    private static final long INITIAL_PROCESSING_TIME = 2 * DELAY;&lt;br /&gt;
    private static Timer timer = null;&lt;br /&gt;
    private boolean firstTime = true;&lt;br /&gt;
    &lt;br /&gt;
    /** &lt;br /&gt;
     * This method will be called during every tick of the Timers.&lt;br /&gt;
     * We insert an artificial delay each time, to simulate some processing.&lt;br /&gt;
     * The first time through, this delay is greater than the delay between&lt;br /&gt;
     * timing events, so that we can see how this hiccup is handled by&lt;br /&gt;
     * fixed-rate and fixed-delay timers.&lt;br /&gt;
     */&lt;br /&gt;
    public void actionPerformed(ActionEvent ae) {&lt;br /&gt;
        long nowTime = System.currentTimeMillis();&lt;br /&gt;
        long elapsedTime = nowTime - prevTime;&lt;br /&gt;
        long totalTime = nowTime - startTime;&lt;br /&gt;
        System.out.println(&amp;quot;Elapsed time = &amp;quot; + elapsedTime);&lt;br /&gt;
        if (totalTime &amp;gt; DURATION) {&lt;br /&gt;
            timer.stop();&lt;br /&gt;
        }&lt;br /&gt;
        prevTime = nowTime;&lt;br /&gt;
        try {&lt;br /&gt;
            if (firstTime) {&lt;br /&gt;
                Thread.sleep(INITIAL_PROCESSING_TIME);&lt;br /&gt;
                firstTime = false;&lt;br /&gt;
            } else {&lt;br /&gt;
                Thread.sleep(PROCESSING_TIME);&lt;br /&gt;
            }&lt;br /&gt;
        } catch (Exception e) {}&lt;br /&gt;
    }&lt;br /&gt;
    public SwingTimerDemo() {&lt;br /&gt;
        firstTime = true;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public static void main(String[] args) {        &lt;br /&gt;
        // Run a default fixed-delay timer&lt;br /&gt;
        timer = new Timer(DELAY, new SwingTimerDemo());&lt;br /&gt;
        startTime = prevTime = System.currentTimeMillis();&lt;br /&gt;
        System.out.println(&amp;quot;Fixed Delay Times&amp;quot;);&lt;br /&gt;
        timer.start();&lt;br /&gt;
        // Sleep for long enough that the first timer ends&lt;br /&gt;
        try {&lt;br /&gt;
            Thread.sleep(DURATION*2);&lt;br /&gt;
        } catch (Exception e) {}&lt;br /&gt;
        &lt;br /&gt;
        // Run a timer with no coalescing to get fixed-rate behavior&lt;br /&gt;
        timer = new Timer(DELAY, new SwingTimerDemo());&lt;br /&gt;
        startTime = prevTime = System.currentTimeMillis();&lt;br /&gt;
        timer.setCoalesce(false);&lt;br /&gt;
        System.out.println(&amp;quot;\nFixed Rate Times&amp;quot;);&lt;br /&gt;
        timer.start();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Tick Tock with an Inner Class ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import javax.swing.JOptionPane;&lt;br /&gt;
import javax.swing.Timer;&lt;br /&gt;
public class TickTockInner {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    TickTockInner t = new TickTockInner();&lt;br /&gt;
    t.go();&lt;br /&gt;
  }&lt;br /&gt;
  private void go() {&lt;br /&gt;
    Timer t = new Timer(1000, new Ticker());&lt;br /&gt;
    t.start();&lt;br /&gt;
    JOptionPane.showMessageDialog(null, &amp;quot;Click OK to exit program&amp;quot;);&lt;br /&gt;
    System.exit(0);&lt;br /&gt;
  }&lt;br /&gt;
  class Ticker implements ActionListener {&lt;br /&gt;
    private boolean tick = true;&lt;br /&gt;
    public void actionPerformed(ActionEvent event) {&lt;br /&gt;
      if (tick) {&lt;br /&gt;
        System.out.println(&amp;quot;Tick...&amp;quot;);&lt;br /&gt;
      } else {&lt;br /&gt;
        System.out.println(&amp;quot;Tock...&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      tick = !tick;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Tick Tock with a Static Inner Class ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import javax.swing.JOptionPane;&lt;br /&gt;
import javax.swing.Timer;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Timer t = new Timer(1000, new Ticker());&lt;br /&gt;
    t.start();&lt;br /&gt;
    JOptionPane.showMessageDialog(null, &amp;quot;Click OK to exit program&amp;quot;);&lt;br /&gt;
    System.exit(0);&lt;br /&gt;
  }&lt;br /&gt;
  static class Ticker implements ActionListener {&lt;br /&gt;
    private boolean tick = true;&lt;br /&gt;
    public void actionPerformed(ActionEvent event) {&lt;br /&gt;
      if (tick) {&lt;br /&gt;
        System.out.println(&amp;quot;Tick...&amp;quot;);&lt;br /&gt;
      } else {&lt;br /&gt;
        System.out.println(&amp;quot;Tock...&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      tick = !tick;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Timer: clock label ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import java.awt.BorderLayout;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import java.util.Date;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.JLabel;&lt;br /&gt;
import javax.swing.Timer;&lt;br /&gt;
public class ClockTest extends JFrame {&lt;br /&gt;
  public ClockTest() {&lt;br /&gt;
    super(&amp;quot;Timer Demo&amp;quot;);&lt;br /&gt;
    setSize(300, 100);&lt;br /&gt;
    setDefaultCloseOperation(EXIT_ON_CLOSE);&lt;br /&gt;
    ClockLabel clock = new ClockLabel();&lt;br /&gt;
    getContentPane().add(clock, BorderLayout.NORTH);&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    ClockTest ct = new ClockTest();&lt;br /&gt;
    ct.setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class ClockLabel extends JLabel implements ActionListener {&lt;br /&gt;
  public ClockLabel() {&lt;br /&gt;
    super(&amp;quot;&amp;quot; + new Date());&lt;br /&gt;
    Timer t = new Timer(1000, this);&lt;br /&gt;
    t.start();&lt;br /&gt;
  }&lt;br /&gt;
  public void actionPerformed(ActionEvent ae) {&lt;br /&gt;
    setText((new Date()).toString());&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Time Resolution ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import javax.swing.Timer;&lt;br /&gt;
/*&lt;br /&gt;
 * TimeResolution.java&lt;br /&gt;
 *&lt;br /&gt;
 * Created on May 2, 2007, 3:38 PM&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 2007, Sun Microsystems, Inc&lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   * Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *   * Redistributions in binary form must reproduce the above&lt;br /&gt;
 *     copyright notice, this list of conditions and the following&lt;br /&gt;
 *     disclaimer in the documentation and/or other materials provided&lt;br /&gt;
 *     with the distribution.&lt;br /&gt;
 *   * Neither the name of the TimingFramework project nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT&lt;br /&gt;
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&lt;br /&gt;
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,&lt;br /&gt;
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY&lt;br /&gt;
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT&lt;br /&gt;
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE&lt;br /&gt;
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 *&lt;br /&gt;
 * @author Chet&lt;br /&gt;
 */&lt;br /&gt;
public class TimeResolution implements ActionListener {&lt;br /&gt;
    &lt;br /&gt;
    private static int INCREMENT = 5;&lt;br /&gt;
    private static int MAX = 50;&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * Measures how much time has elapsed according to both currentTimeMillis()&lt;br /&gt;
     * and nanoTime() at each interval. Note that the time reported for &lt;br /&gt;
     * sleep() may not be accurate since the internal sleep timer may not&lt;br /&gt;
     * have the appropriate resolution to sleep for the requested time.&lt;br /&gt;
     * The main utility of this function is to compare the two timing&lt;br /&gt;
     * functions, although it is also interesting to see how the measured&lt;br /&gt;
     * time varies from the sleep() time.&lt;br /&gt;
     */&lt;br /&gt;
    private void measureTimeFunctions(int increment, int max) {&lt;br /&gt;
        long startTime = System.currentTimeMillis();&lt;br /&gt;
        long startNanos = System.nanoTime();&lt;br /&gt;
        long elapsedTimeActual = 0;&lt;br /&gt;
        long elapsedTimeMeasured = 0;&lt;br /&gt;
        long elapsedNanosMeasured = 0;&lt;br /&gt;
        System.out.printf(&amp;quot;sleep   currentTimeMillis   nanoTime\n&amp;quot;);&lt;br /&gt;
        while (elapsedTimeActual &amp;lt; max) {&lt;br /&gt;
            try {&lt;br /&gt;
                Thread.sleep(increment);&lt;br /&gt;
            } catch (Exception e) {}&lt;br /&gt;
            long currentTime = System.currentTimeMillis();&lt;br /&gt;
            long currentNanos = System.nanoTime();&lt;br /&gt;
            elapsedTimeActual += increment;&lt;br /&gt;
            elapsedTimeMeasured = currentTime - startTime;&lt;br /&gt;
            elapsedNanosMeasured = (currentNanos - startNanos) / 1000000;&lt;br /&gt;
            System.out.printf(&amp;quot; %3d           %4d          %4d\n&amp;quot;,&lt;br /&gt;
                    elapsedTimeActual, elapsedTimeMeasured, elapsedNanosMeasured);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * This method measures the actual time slept, compared to the requested&lt;br /&gt;
     * sleep() time. We run many iterations for each value of sleep() to&lt;br /&gt;
     * get more accurate timing values; this accounts for possible &lt;br /&gt;
     * inaccuracies of our nanoTime() method for small time differences.&lt;br /&gt;
     */&lt;br /&gt;
    private void measureSleep() {&lt;br /&gt;
        System.out.printf(&amp;quot;                                 measured\n&amp;quot;);&lt;br /&gt;
        System.out.printf(&amp;quot;sleep time   iterations   total time   per-sleep\n&amp;quot;);&lt;br /&gt;
        for (int sleepTime = 0; sleepTime &amp;lt;= 20; ++sleepTime) {&lt;br /&gt;
            int iterations = (sleepTime == 0) ? 10000 : (1000 / sleepTime);&lt;br /&gt;
            long startTime = System.nanoTime();&lt;br /&gt;
            for (int i = 0; i &amp;lt; iterations; ++i) {&lt;br /&gt;
                try {&lt;br /&gt;
                    Thread.sleep(sleepTime);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            long endTime = System.nanoTime();&lt;br /&gt;
            long totalTime = (endTime - startTime) / 1000000;&lt;br /&gt;
            float calculatedSleepTime = totalTime / (float)iterations;&lt;br /&gt;
            System.out.printf(&amp;quot;   %2d          %5d         %4d       %5.2f\n&amp;quot;, &lt;br /&gt;
                    sleepTime, iterations, totalTime, calculatedSleepTime);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * This method is like the measureSleep() method above, only for the&lt;br /&gt;
     * wait() method instead of sleep().&lt;br /&gt;
     */&lt;br /&gt;
    private synchronized void measureWait() {&lt;br /&gt;
        System.out.printf(&amp;quot;                                measured\n&amp;quot;);&lt;br /&gt;
        System.out.printf(&amp;quot;wait time   iterations   total time   per-wait\n&amp;quot;);&lt;br /&gt;
        for (int sleepTime = 1; sleepTime &amp;lt;= 20; ++sleepTime) {&lt;br /&gt;
            int iterations = (sleepTime == 0) ? 10000 : (1000 / sleepTime);&lt;br /&gt;
            long startTime = System.nanoTime();&lt;br /&gt;
            for (int i = 0; i &amp;lt; iterations; ++i) {&lt;br /&gt;
                try {&lt;br /&gt;
                    wait(sleepTime);&lt;br /&gt;
                } catch (Exception e) {&lt;br /&gt;
                    System.out.println(&amp;quot;Exception: &amp;quot; + e);&lt;br /&gt;
                    Thread.dumpStack();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            long endTime = System.nanoTime();&lt;br /&gt;
            long totalTime = (endTime - startTime) / 1000000;&lt;br /&gt;
            float calculatedSleepTime = totalTime / (float)iterations;&lt;br /&gt;
            System.out.printf(&amp;quot;  %2d          %5d         %4d       %5.2f\n&amp;quot;, &lt;br /&gt;
                    sleepTime, iterations, totalTime, calculatedSleepTime);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    // Variables used in measurement of Swing timer&lt;br /&gt;
    int timerIteration = 0;&lt;br /&gt;
    int iterations = 0;&lt;br /&gt;
    Timer timer;&lt;br /&gt;
    long startTime, endTime;&lt;br /&gt;
    int sleepTime;&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * This method is called during the execution of the Swing timer.&lt;br /&gt;
     */&lt;br /&gt;
    public void actionPerformed(ActionEvent ae) {&lt;br /&gt;
        if (++timerIteration &amp;gt; iterations) {&lt;br /&gt;
            timer.stop();&lt;br /&gt;
            timerIteration = 0;&lt;br /&gt;
            endTime = System.nanoTime();&lt;br /&gt;
            long totalTime = (endTime - startTime) / 1000000;&lt;br /&gt;
            float calculatedDelayTime = totalTime / (float)iterations;&lt;br /&gt;
            System.out.printf(&amp;quot;  %2d          %5d         %5d        %5.2f\n&amp;quot;, &lt;br /&gt;
                    sleepTime, iterations, totalTime, calculatedDelayTime);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
       &lt;br /&gt;
    /**&lt;br /&gt;
     * This method measures the accuracy of the Swing timer, which is &lt;br /&gt;
     * internally dependent upon both the internal timing mechanisms&lt;br /&gt;
     * (either currentTimeMillis() or nanoTime()) and the wait() method.&lt;br /&gt;
     * So the results we see here should be predictable from the results&lt;br /&gt;
     * we see in the other measurement methods.&lt;br /&gt;
     */&lt;br /&gt;
    public void measureTimer() {&lt;br /&gt;
        System.out.printf(&amp;quot;                                  measured\n&amp;quot;);&lt;br /&gt;
        System.out.printf(&amp;quot;timer delay   iterations   total time   per-delay\n&amp;quot;);&lt;br /&gt;
        for (sleepTime = 0; sleepTime &amp;lt;= 20; ++sleepTime) {&lt;br /&gt;
            iterations = (sleepTime == 0) ? 1000 : (1000 / sleepTime);&lt;br /&gt;
            timerIteration = 1;&lt;br /&gt;
            timer = new Timer(sleepTime, this);&lt;br /&gt;
            startTime = System.nanoTime();&lt;br /&gt;
            timer.start();&lt;br /&gt;
            while (timerIteration &amp;gt; 0) {&lt;br /&gt;
                try {&lt;br /&gt;
                    Thread.sleep(1000);&lt;br /&gt;
                } catch (Exception e) {}&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Execute the various timer resolution tests.&lt;br /&gt;
     */&lt;br /&gt;
    public static void main(String args[]) {&lt;br /&gt;
        TimeResolution timeResolution = new TimeResolution();&lt;br /&gt;
        timeResolution.measureTimer();&lt;br /&gt;
        timeResolution.measureTimeFunctions(INCREMENT, MAX);&lt;br /&gt;
        timeResolution.measureSleep();&lt;br /&gt;
        timeResolution.measureWait();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Timer Sample ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import javax.swing.JFrame;&lt;br /&gt;
import javax.swing.Timer;&lt;br /&gt;
public class TimerSample {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    new JFrame().setVisible(true);&lt;br /&gt;
    ActionListener actionListener = new ActionListener() {&lt;br /&gt;
      public void actionPerformed(ActionEvent actionEvent) {&lt;br /&gt;
        System.out.println(&amp;quot;Hello World Timer&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
    };&lt;br /&gt;
    Timer timer = new Timer(500, actionListener);&lt;br /&gt;
    timer.start();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Timer with ProgressBar ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import javax.swing.*;&lt;br /&gt;
import java.awt.*;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import java.text.SimpleDateFormat;&lt;br /&gt;
import java.util.Calendar;&lt;br /&gt;
public class TimerExample extends JPanel implements ActionListener {&lt;br /&gt;
    private Timer timer = new Timer(100, this);&lt;br /&gt;
    private JLabel clockLabel;&lt;br /&gt;
    private Calendar calendar = Calendar.getInstance();&lt;br /&gt;
    private SimpleDateFormat dateFormat = new SimpleDateFormat(&amp;quot;h:mm ss a&amp;quot;);&lt;br /&gt;
    private JProgressBar secondsProgressBar = new JProgressBar(0, 1000);&lt;br /&gt;
    public TimerExample() {&lt;br /&gt;
        this.clockLabel = new JLabel(&amp;quot;Clock Stopped&amp;quot;);&lt;br /&gt;
        this.clockLabel.setFont(this.clockLabel.getFont().deriveFont(Font.BOLD, 16));&lt;br /&gt;
        this.clockLabel.setHorizontalTextPosition(JLabel.CENTER);&lt;br /&gt;
        this.secondsProgressBar.setVisible(false);&lt;br /&gt;
        this.secondsProgressBar.setForeground(Color.blue);&lt;br /&gt;
        add(this.clockLabel);&lt;br /&gt;
        add(secondsProgressBar);&lt;br /&gt;
        add(new JButton(new ToggleClockAction()));&lt;br /&gt;
    }&lt;br /&gt;
    private class ToggleClockAction extends AbstractAction {&lt;br /&gt;
        private String startClock = &amp;quot;Start Clock&amp;quot;;&lt;br /&gt;
        private String stopClock = &amp;quot;Stop Clock&amp;quot;;&lt;br /&gt;
        private String clockStopped = &amp;quot;Clock Stopped&amp;quot;;&lt;br /&gt;
        public ToggleClockAction() {&lt;br /&gt;
            super();&lt;br /&gt;
            putValue(Action.NAME, startClock);&lt;br /&gt;
        }&lt;br /&gt;
        public void actionPerformed(ActionEvent e) {&lt;br /&gt;
            if (TimerExample.this.timer.isRunning()) {&lt;br /&gt;
                putValue(Action.NAME, startClock);&lt;br /&gt;
                TimerExample.this.timer.stop();&lt;br /&gt;
                TimerExample.this.secondsProgressBar.setVisible(false);&lt;br /&gt;
                TimerExample.this.clockLabel.setText(clockStopped);&lt;br /&gt;
            } else {&lt;br /&gt;
                putValue(Action.NAME, stopClock);&lt;br /&gt;
                // Call Action Performed To Initialize Time Before Timer is Started.&lt;br /&gt;
                // Null is ok since we ignore the event.&lt;br /&gt;
                TimerExample.this.actionPerformed(null);&lt;br /&gt;
                TimerExample.this.secondsProgressBar.setVisible(true);&lt;br /&gt;
                TimerExample.this.timer.start();&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void actionPerformed(ActionEvent e) {&lt;br /&gt;
        this.calendar.setTimeInMillis(System.currentTimeMillis());&lt;br /&gt;
        this.clockLabel.setText(this.dateFormat.format(this.calendar.getTime()));&lt;br /&gt;
        int milliseconds = this.calendar.get(Calendar.MILLISECOND);&lt;br /&gt;
        this.secondsProgressBar.setValue(milliseconds);&lt;br /&gt;
    }&lt;br /&gt;
    public void endExample() {&lt;br /&gt;
        this.timer.stop();&lt;br /&gt;
    }&lt;br /&gt;
    public static void main(String[] a){&lt;br /&gt;
      JFrame f = new JFrame();&lt;br /&gt;
      f.setDefaultCloseOperation(1);&lt;br /&gt;
      f.add(new TimerExample());&lt;br /&gt;
      f.pack();&lt;br /&gt;
      f.setVisible(true);&lt;br /&gt;
    } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>