• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why dose applets have init method and applications dont

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ,
i have a doubt with me for a long time . why dose applets have init method . and altogether a different life cycle to that of applications ... can anyone pls clarify my doubt ....
the answer to this question is greatly appreciated
vijay kumar
 
Tom P
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple. It's because the main method is inside the browser. The browser is running your applet as a sub-program of the browser.
[This message has been edited by Tom P (edited May 15, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Mr Tom
thanks for clarifying my doubt .
I have one more question to ask ....
As u said the applet is running as a sub program in the browser and main method is in the browser . in that case the browser's main method must be creating an instance of the applet .and calling the init method for initialisation . but it instead applets could have a constructor to do the initialisation why only init for intitialisation?.
vijay kumar
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is because the Browser would have to know what parameters to give your constructor, and where to get them from. Imagine I have

How would the browser know which constructor to call, and how would it know what to pass in?
In general it's much simpler to require the presence of a particular "init" method, with particular parameters, and leave constructing the Object to the default (no parameters) constructor.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ,
what iff i keep all my code in the init method in the default constructor and dont have any init method ... will that be working the same way as it is with the init method . if so then the question is back again why init. go for giving all initialisatio in the default constructor and forget
if my interpretation still has got some logical problem pls explain
thanks
vijay kumar
 
Tom P
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about what it looks like to the browser. It has an object of type Applet not an object of type MyApplet. It isn't going to run the constructor because if it does it would be running the constructor for Applet! So it knows that every object of type Applet has an init() method so that is what the browser will run.
[This message has been edited by Tom P (edited May 16, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
if browser has the object of Applet then how can it call the inti method of MyApplet. I am not clear . pls explain me.
vijay kumar
 
Tom P
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because MyApplet extends Applet and is therefore an object of type Applet. All objects of type Applet have an init() method.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic