In Swing and AWT, there is the Event Dispatcher
Thread (EDT). This is one single thread that does many things, including handling user input (typing, mouse clicks, etc) and repainting the user interface. This means you shouldn't do anything lengthy in the EDT, and that includes code inside listeners. Otherwise, when you click a button, the entire user interface hangs until that handling method ends.
Another important issue is that changes to the user interface should be done from the EDT as well, or you may get errors. I've seen lots of ArrayIndexOutOfBoundsExceptions because changes were done from another thread.
You said you want to repaint every 10 seconds. That means you need to use some kind of timer. That Thread.sleep(1000 * 10) is wrong for two reasons:
1) it is one single sleep of 10.000 milliseconds (10 seconds).
2) if you do this in the EDT your user interface will do nothing else for the full 10 seconds.
Now, as timers are concerned, there are two available in the API:
- java.util.Timer
- javax.swing.Timer
Both could do what you want but the second has one advantage: it runs on the EDT. That means you don't have to perform "tricks" like using EventQueue.invokeLater. You can simply put your code in the ActionListener's actionPerformed method and be done.
So, for example: