Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse the contents of a Swing thread

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to parse the content of Swing threads, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

one。 Event

1. Event source: local system, application itself

two。 All events are stored in a queue

3.Java.awt.EventQueue takes data from the queue and dispatches it, and the dispatch mechanism of EventQueue is handled by a separate thread, EDT (Event Dispatch Thread).

two。 Draw

As described in the previous section, paintImmediately () is like an entry that tells a Swing control to draw itself and make sure that all the required painting occurs correctly. This method may also be used to make synchronous drawing requests. As its name implies, sometimes a control needs to change its appearance in real time according to its internal state. (e.g. It's like when a JScrollPane scrolls.

The program should not call this method directly unless there is a need for real-time rendering. This is because asynchronous repaint () causes multiple overlapping requests to be effectively merged, while the direct call to paintImmediately () does not. In addition, the rule for calling this method is that it must be called from the event allocation thread; it is not designed for your multithreaded drawing code! For details of Swing's single-threaded mode, see the collected article Swing Thread.

1.Swing threads include: main thread (the main method of the application), toolkit thread (capturing system events), EDT (dispatching captured threads)

two。 Asynchronous redraw requests: all asynchronous requests are variants of repaint (), including the drawing of the entire build and the drawing of an area

3. Synchronous drawing request: Jcomponent.paintImmediately () and Component.paint ()

three。 Render

1. Painter algorithm

2.paintComponent ()

3.paint ()

4.setpaque ()

four。 Double buffering

The superclass of JSci.swing is an abstract class called JDoubleBufferedComponent. This class is relatively simple and provides double buffering for the graphics on which it will be built. Double buffering indicates whether the receiving component should use a buffer to paint. If double buffering is set to true, then all drawings from this component will be done in the offscreen drawing buffer. The off-screen painting buffer will be copied to the screen later. According to the Javadocs,Swing drawing system, double buffers are always used. If a component has a buffer and one of its parent components also has a buffer, then the buffer of its parent component is used.

JDoubleBufferedComponent relies on its own double buffering rather than Swing's double buffering to implement JComponent processing double buffering. This provides developers using JSci.swing packages with finer-grained control over double buffering than just using Swing.

Five. Swing thread

1.Swing threads include: main thread (the main method of the application), toolkit thread (capturing system events), EDT (dispatching captured threads)

two。 Threading model: a single rule, so follow this rule and let EDT dispatch events as much as possible.

3.invokeLater ()

4.isEventDispatchThread ()

5.invokeAndWait

six。 Timer and event dispatch

1.java.util.Timer

2.javax.swing.Timer

VII. SwingWorker

1.done ()

2.doInBackground ()

3.get

4.process

On how to parse the content of Swing threads to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report