title: Timer in java using Eclipse
body: <p>I'm trying to do a little program in Java using Eclipse, and I'm a little bit lost.</p>
  
  <p>Could anybody explain me (in a "for dummies way") what do I have to do for repaint a form using a timer?</p>
  
  <p>I'm trying to do something as simple as a clock. I need a timer to repaint it every second. </p>
  
  <p>Something like this:</p>
  
  <pre><code>private void activateTimer()
  {
      ActionListener myAction;
      myAction = new ActionListener () 
      { 
          public void actionPerformed(ActionEvent e) 
          { 
             whatever.redraw();
           } 
  
      };
      myTimer = new Timer(1000, myAction);
      myTimer.start();
  }
  </code></pre>
  
  <p>When the action must be performed, I receive the error:</p>
  
  <pre><code>*Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid thread access*
  </code></pre>
  
  <p>This is the full exception I receive:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid thread access
      at org.eclipse.swt.SWT.error(SWT.java:4282)
      at org.eclipse.swt.SWT.error(SWT.java:4197)
      at org.eclipse.swt.SWT.error(SWT.java:4168)
      at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
      at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:359)
      at org.eclipse.swt.widgets.Control.redraw(Control.java:2327)
      at default.myTimer$1.actionPerformed(myTimer.java:97)
      at javax.swing.Timer.fireActionPerformed(Unknown Source)
      at javax.swing.Timer$DoPostEvent.run(Unknown Source)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$000(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>
  
  <p>Any idea or any sample about refreshing a screen every second?</p>
  
  <p>I've followed the instructions in one of the answers but I'm still receiving the same error. </p>