The event handling mechanism of Java swing
after the Swing GUI is started , the Java Virtual machine launches three threads, namely the main thread, the event dispatch thread (also the event processing thread), and the System Toolkit thread.
- Main thread: Responsible for creating and displaying the initial interface of the program;
- System Toolkit Thread: Responsible for capturing the underlying events such as mouse and keyboard actions from the System event queue on the program interface, and converting these events into
The corresponding event object of swing is placed in the event queue of swing and loops the thread;
- Event Dispatch Thread: responsible for drawing and updating GUI components, by constantly getting events from the event queue and invoking event handlers for event listeners to
Handles events to interact, and the process loops until the program exits.
Java Swing Event Processing Model : (same as for Android event handling)
- Event source;
- Registering event listeners;
- Event Listener
Java Swing event handling mechanism