In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to describe the goal of Swing, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Goals achieved by Swing
According to the goals achieved by Swing, developers who develop java interfaces are divided into two categories: the first is to develop independent components, which have nothing to do with specific applications. Swing itself also provides a set, developers can also develop their own components, these people are component developer roles. The next step is to build GUI for an application, to build component instances using those component classes, and to implement interface requirements by establishing container relationships. These are GUI developer roles. From this clear division, we can understand the spirit of Swing OO-oriented development. Each component developed by a component developer is a highly abstract, packaged class for all applications, so it is highly reused. On the other hand, the development process of GUI developers is to continue OO---, as needed. First, the entire application interface responsibility is encapsulated into a class, and the life cycle of the instance of this class represents the life cycle of the entire application interface. Then the interface responsibility is divided from the point of view of the application domain, using the container concept and quickly through aggregation. Custom component instances create a "panel class / page class" that undertakes the responsibility of interface interaction in various application areas. * application interface class instances will continue to couple and entrust all kinds of "panel class / page class" instances throughout the life cycle (generally achieve dynamic through "page interface") to complete all interface interaction responsibilities.
On the other hand, Swing is born to meet the needs of such oo practices. In the gui builds described above, the most frequent is to assemble specific panel components through a container. So how do you customize the distribution of subcomponents on the container panel?
The goal of Swing is to setLayout (LayoutManager mgr) in Container. The mgr provides a layout method, such as five-bit map layout or table layout. When sub-components join the container, you can give their respective layout information for this container layout, Container.add (Component comp, Object constraints). * * when drawing the sub-components of the container, you can calculate the appropriate size and position of each component according to these layout information. However, in Swing, in order to improve performance, instead of re-calculating how to draw the subcomponents according to the layout information each time, the drawing requirements calculated according to the layout information will be stored in the subcomponents and containers in one process, such as the position of the adjusted subcomponents, the appropriate size of the container, etc., and will be drawn directly later. Unless there is a layout change, such as the loss of a sub-component of the container remove, it will lead to a process of recalculating the layout information. Because the component relationship in Swing is a layer of package, a change in one layer may cause the whole tree to be recalculated, which is similar to the repaint scenario. Therefore, Swing will adopt a repaint-like submission request waiting for processing mode, that is, the legendary revalidate. Let's take a look at the specific implementation in jre1.7:
PublicclassJComponent {publicvoidrevalidate () {if (getParent () = = null) {return;} if (SwingUtilities.isEventDispatchThread ()) {invalidate (); / invalidate the component layout RepaintManager.currentManager (this) .addInvalidComponent (this); / / request RM for a relayout} else {/ / if it is not called in EDT, it needs to be adjusted to EDT. / / ToavoidafloodofRunnableswhenconstructingGUIsoff / / theEDT,aflagismaintainedastowhetherornot / / aRunnablehasbeenscheduled. Synchronized (this) {if (getFlag (REVALIDATE_RUNNABLE_SCHEDULED)) {return;} setFlag (REVALIDATE_RUNNABLE_SCHEDULED,true);} RunnablecallRevalidate=newRunnable () {publicvoidrun () {synchronized (JComponent.this) {setFlag (REVALIDATE_RUNNABLE_SCHEDULED,false);} revalidate ();}; SwingUtilities.invokeLater (callRevalidate);}} after reading the above, do you know how to describe the goals achieved by Swing? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.