by Dinesh Thakur Category: AWT and Applets

One of the important architectural constraints that have been imposed on an applet is that it must quickly return control to the AWT run-time system. It cannot create a loop inside paint( ). This would prevent control from passing back to the AWT. Whenever your applet needs to update the information displayed in its window, it simply calls repaint( ). The repaint( ) method is defined by the AWT that causes AWT run-time system to execute a call to your applet's update() method, which in turn calls paint(). The AWT will then execute a call to paint( ) that will display the stored information. The repaint( ) method has four forms. The simplest version of repaint( ) is:


void repaint ( )


This causes the entire window to be repainted. Other versions that will cause repaint are:


void repaint(int left, int top, int width, int height)


If your system is slow or busy, update( ) might not be called immediately. If multiple calls have been made to AWT within a short period of time, then update( ) is not called very frequently. This can be a problem in many situations in which a consistent update time is necessary. One solution to this problem is to use the following forms of repaint( ):


void repaint (long maxDelay)

void repaint (long maxDelay, int x, int y, int width, int height)


Here, maxDelay specifies the maximum number of milliseconds that can elapse before update( ) is called. If the time elapses before update( ) can be called, it isn't called. It is possible for a method other than paint( ) or update( ) to output to an applet's window. To do so, it must obtain a graphics context by calling getGraphics( ) and then use this context to output to the window. For most applications, it is better and easier to route window output through paint( ) and to call repaint( ) when the contents of the window change .

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles