APPLET With Demo Example

APPLET With Demo Example





Applet methods

Basic methods :-
- public void init ()
- public void start () 
- public void stop () 
- public void destroy ()

Other Supplementary methods :-
- public void showStatus(String)
- public String getParameter(String) 

How a Java Applet works??? 



- You write an applet by extending the class Applet 
- Applet class defines methods as  
    - init( ) 
    - start( ) 
    - stop( ) 
    - destroy( ) 
    - and some others…  

- These methods do not do anything 
    - They are stubs  

- You make the applet do something by overriding these methods   
- You don’t need to override all these methods  
- Just the ones you care about 

1).Method init( ) 

- This is the first of your methods to be executed 
- It is automatically called by the system when the JVM launches the applet for the first time  
- It is only executed once  ò It is the best place to  
- Initialize variables  ø Define the GUI Components · 
   E.g. buttons, text fields, scrollbars, etc. 
- Lay the components out 
- Add listeners to these components  
- Pick up any HTML parameters  
- Almost every applet you ever write will have an 10  Fall 2007  init( ) of your methods to be executed It is automatically called by the system when the JVM launches the 
     E.g. buttons, text fields, scrollbars, etc. to these components  any HTML parameters  Almost every applet you ever write will have an init( ) method

2).Method start( )

- Not usually needed ò It is automatically called after the JVM calls the 
- Also called whenever a user returns to the HTML page containing the applet after having gone to other pages  
- i.e. each time the page is loaded and restarted 
- Can be called repeatedly  
- Common place to restart a thread ·
    E.g. resuming an animation  
- Used mostly in conjunction with stop( ) 


3).Method stop( ) 

- Not usually needed 
- It is automatically called when the user moves off the page on which  the applet sits  
- Can be called repeatedly in the same applet  
- Called just before destroy( ) 
- Gives a chance to stop time­consuming activity  the system when the user is not paying attention to the applet  
- Should not be called directly  
- Used mostly in conjunction with start( ) 


4).Method destroy( ) 

- Almost never needed 
-Called after stop( ) 
- The JVM guarantees to call this method when the browser shuts down  normally  
- Use to explicitly release system resources  
- E.g. threads  
- System resources are usually released 
- Commonly used for reclaiming non13  Fall 2007  destroy( ) The JVM guarantees to call this method when the browser shuts down  system resources  System resources are usually released automatically  ­memory­dependent resources


PDF Reference(G-Drive Link)

https://drive.google.com/open?id=13wjWpdNbTRc17tZlJAVkcAw94pvME4hG






Don't Forget to Share your Opinion About This post in Comment Section, Your One Comment Will Not only Make Our day But will Make our Year. And Do mention Of you have any ideas for our Blog:)



Post a Comment

0 Comments