java - How does paintComponent work? -
This can be a very naw question, I'm just starting learning Java
The operation of the compound method is not understood. I know that I want to attract something, I have to override the paint compendant method.
Public Zero Paint (Graphics G) {...} But when is it called? I do not see anything like "object.paintComponent (g)", but still the program is ready when it is ready.
And what is the graphics parameter? where is it from? The parameter should be provided when the method is called. But as I said earlier, it seems that this method is never called clearly. So what does this parameter provide? And why do we have to put it in Graphics 2D?
Public Zero Paint Head (Graphics G) {... Graphics 2DG2 = (Graphics 2D) G; ...}
The short answer (too) of your question is that Paint Component is called "when it is needed" Sometimes the Java swing GUI system is easy to think of as a "black box", where most of the interior is handled without much visibility. There are several factors that determine when a component is needed to paint again, moving, re-shaping, changing the focus, is hidden from other frames, and so on as well. Many of these incidents are auto-magically detected, and paintComponent is said internally when it is determined that this operation is necessary. I've worked with swing for many years, and I do not think I've ever referred ever to paintComponent , or even seen it The most closest thing I can do is to trigger a redesign of some components from programming (which I call the correct paintComponent methods downstream) to repaint () methods. is using. In my experience, paintComponent rarely overrides. I believe there are custom rendering functions that require such granularity, but Java swing provides a strong (strong) set of JComponents and layouts directly without overriding the paintComponent Used to carry more loads. I think my point here is that you can not do anything with the original JComponents and layout before you roll your own custom-render components.
Comments
Post a Comment