Sunday, July 4, 2010

Applet Methods

init( )

The init( ) method is the first method to be called. This is where variables are initialized. This method is called only once during the run time of your applet.

start( )

The start( ) method is called after init( ). It is also called to restart an applet after it has been stopped. start( ) is called each time an applet’s HTML document is displayed onscreen. So, if a user leaves a web page and comes back, the applet resumes execution at start( ).

paint( )

paint( ) is called after start(). The paint( ) method is called each time your applet’s output must be redrawn due to the applet window being overwritten by another window and then uncovered or the applet window may be minimized and then restored. The paint( ) method has one parameter of type Graphics. This parameter will contain the graphics context, which describes the graphics environment in which the applet is running. This context is used whenever output to the applet is required.

stop( )

The stop( ) method is called when a web browser navigates away from the page containing the applet. stop( ) is used to suspend threads that don’t need to run when the applet is not visible. You can restart them when start( ) is called if the user returns to the page.

destroy( )

The destroy( ) method is called when the environment determines that your applet needs to be removed completely from memory. At this point, you should free up any resources the applet may be using. The stop( ) method is always called before destroy( ).

No comments:

Post a Comment