Requesting Repainting

As a general rule, an applet writes to its window only when its update( ) or paint( )
method is called by the AWT. This raises an interesting question: How can the applet itself cause its window to be updated when its information changes? For example, if and  applet is displaying a moving banner, what mechanism does the applet use to update the wind ‘ow each time this banner scrolls? Remember, one of the fundamental architectural constraints imposed on an applet is that it must quickly return control to the AWT run-timesystern.It cannot create a loop inside paint() that repeatedly scrolls the banner, for example. This would prevent control from passing back to the AWT. Given this constraint, it may seem that output to your applet’s window will be difficult at best. Fortunately, this is not the case. Whenever your applet needs to update the information displayed in its window, it  The repaint( ) method is defined by the AWT. It causes the Awr run-time system to executes call to your applet’s update() method, which, in its default implementation, . Thus, for another part of your applet to output to its I . window, simply store the output and then call repaint( ). The AWT will then execute a call to paint( ), which can display the stored information. For example, if part: of your applet needs to output a string, it can store this string in a String variable and then Inside  you will output the string using draw String().  The  method has four forms. Let’s look one, in turn. The simplest version of repaint( ) is shown here.

Here, the coordinates of the upper-left corner of the region arc specified by left and top, and the width and height of the region arc passed in width and height. These dimensions arc specified in pixels. You save time by specifying a region to repaint. Willdow updates are costly in terms of time. If you need to update only a small portion of the window, it is more efficient to repaint only that region. Calling repaint() is essentially a request that your applct be repainted sometime soon. However, if your system is slow or busy, up datet ) might not be called immediately. Multiple requests for repainting that occur within a short time can be collapsed by the AvVT in a manner such that update] ) is only called sporadically. This can be a problem in many situations, including animation, in which a consistent update time is necessary. One solution to this problem is to use the following forms of repaint .

[vfb id=1]

Share This