Java swingRepainting and dual-Buffer Optimization
Cause: I want to write a question in the past two days.21Point game, when using the formJframe, Flash is serious. After special processing, it will be slightly better.AWTInsideFrame, No flashes after dual buffering.
Here we will discuss the painting problem in swing. There is no update () in the painting process in swing. By default, it is double buffering, but I don't know why it will flash. OnProgramIn the paint method, a dual-buffer front-and-backend alternate mechanism is written, which can be transient. Finally, a slightly better solution is to draw P1 at the front end and P2 at the back end, in the next cycle, the front-end draws P2, the back-end draws P3, and so on, so that the CPU will not be too tight, and the flickering phenomenon will be greatly improved.
The Drawing Mechanism of swing and AWT is very different. After switching to AWT, it is not a flash, so it is really depressing!