I have see something about thread, implements Runnable
Forget that you ever saw that. That was a bad idea that ought to be deprecated. If you want to create an explicit thread in a java program, do it like this:
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
...code to be run in the thread goes here...
}
});
I'm not going to explain why in this space, but just trust me. It's a good habit to get into now.
what does this do? ...invokeLater...
The swing package creates a thread that responds to "events" (mouse clicks, key presses, etc.), and a lot of the code that you write for swing runs as "handlers" that are called by that thread.
Sometimes, your handler wants to do something that is not allowed/does not make sense in the context in which it is called. I'm not a swing programmer, so I don't have a handy example, but the solution is to call invokeLater()
EventQueue invokeLater(new Runnable() {
@Override
public void run() {
...code that you want to run "later"...
}
});
This will post a new event to the event queue, and when the event thread picks it off the queue, it will execute the run() method that you provided.