We know that the painting method is called every time you repaint in Java.
Public void paint (Graphics g )...{
// Super. Paint (g );
Color c = G. getcolor ();
G. setcolor (new color (50,150, 50 ));
G. filloval (tankpos. X, tankpos. Y, tankwid, tankhei );
G. setcolor (C );
} If the frame class in the AWT package is used to construct the window, the above method is correct. However, if the jframe class in swing is used as its subclass, it will be re-painted each time, only the elements in the border and painting method of the window are repainted. The background of the window is not drawn. Therefore, the window displays the items to be displayed in the next window, is "Transparent. Moreover, if the program you write is an animation effect, the last frame after repainting will not be automatically cleared, but will overlap with the next frame. This means that the frame of its parent class can complete the work (refresh the screen) without doing it.
Therefore, we must first call the painting method of the parent object, namely java. AWT. Frame,
Super. Paint (Graphics
G );
In this case, OK.
Alternatively, you can manually add the screen refresh code to the paint:
G. setcolor (this. getbackground ());
G. fillrect (0,
0, window width, window height );