I will try to answer all three questions. First of all, the order in which the ActionListener fire ActionListener not specified. You should never assume that they will shoot. If you need actions to be performed in a specific order, put them in the same ActionListener .
When programming Swing, you will almost always be in a multi-threaded environment. There is one thread called Thread Dispatch Thread (EDT). This is a thread that processes all events. Any other processing you do must be done in a different thread, otherwise your Swing GUI may stop responding.
The usual case for multiple threads in Swing is when you need to do some processing, which takes a lot of time. (Intensive computing, IO, database connections). You will want to do the hard work in a separate thread from the EDT. This will support your GUI.
Oracle Network has an excellent Swing concurrency tutorial. I recommend you check it out .
The Swing programmer has the following types of threads:
- Initial threads, threads that execute the application source code.
- an event dispatch thread where all event processing code is executed. Most of the code that interacts with the Swing framework should also run in this thread.
- Workflows, also known as background threads, where time-consuming background tasks are performed.
The canonical answer to any multithreaded questions in Swing is to use SwingWorker . This allows you to easily coordinate the background image in a separate thread using EDT. As usual, Oracle has an excellent tutorial on using SwingWorker .
jjnguy
source share