Differences between the painting method in the Java frame and jframe

Source: Internet
Author: User

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 );




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.