Hi, I have two doubts in mind about constructors and init() method- 1)Since all th initialization is normally done in the init() method then what is the advantage of having a parameterless constructor? Normally I do no have any constructor in my applets. Infact I was under the impression that u cannot have constructors in the applet untill I saw an applet with the constructor. There certain variable were declared in init() and others in a constructor.Wonder Why? . 2)Since the applet works perfectly fine with the constructor I am convinced that one can have a constructor in the applet.This leads to another question which one is called first init() or constructor.If init() is called first then when is the constructor called?Rather which is the place/rank of the constructor in the life cycle of an applet. init()=>start()=>paint()=>stop()=>destroy() Where is constructor? Please....... clarify. Thanx in advance. Best Regards, Kavita.
Hi I don't know about the usage of presence or absence of constructor, but i may be of help in second question. The constructor is called before the init. since init etc. would be called only after the applet object is available to the browser and the constructor is called at the time of instantiation of the applet. Once the object is created, the init etc (the sequence ) starts. hope it clarifies raghav..
Yes, constructor is called first followed by init method. In applets it is preffered to put the "initial" code in init() method rather than in constructor. The reason is, applet generally not gauranteed for full environment until its init method is executed. Take for example, loading big images, which may not properly load and available for applet if they are loaded in constructor instead of init method. Also, execution of init is faster than constructor. Hope, it clears your question.
Originally posted by Kavita Ghia: Hi, I have two doubts in mind about constructors and init() method- 1)Since all th initialization is normally done in the init() method then what is the advantage of having a parameterless constructor? Normally I do no have any constructor in my applets. Infact I was under the impression that u cannot have constructors in the applet untill I saw an applet with the constructor. There certain variable were declared in init() and others in a constructor.Wonder Why? . 2)Since the applet works perfectly fine with the constructor I am convinced that one can have a constructor in the applet.This leads to another question which one is called first init() or constructor.If init() is called first then when is the constructor called?Rather which is the place/rank of the constructor in the life cycle of an applet. init()=>start()=>paint()=>stop()=>destroy() Where is constructor? Please....... clarify. Thanx in advance. Best Regards, Kavita.
Kavita Ghia
Ranch Hand
Joined: Oct 10, 2000
Posts: 91
posted
0
Hi Rao, My question was what is the advantage of having the initialization code in the constructor rather than the applet.Bcoz i have been using only init() for initialization and NOT the CONSTRUCTOR. Reagrds, Kavita.
Kavita Ghia
Ranch Hand
Joined: Oct 10, 2000
Posts: 91
posted
0
Hello friends, I am really keen to know in what way constructors are advantageous to use then the init() method.And if they are not advantageous then why do people use it.Anyone out there please reply as can't think of its usefullness.Maybe somewhere i am overlooking certain point. Regards, Kavita.
Rao Kuna
Greenhorn
Joined: May 07, 2000
Posts: 14
posted
0
It is defenetly preferable to use init method than constructor in Applets. Constructor also works but it is not reliable in some cases and for details, you better go to "sun online tutorial --> subject "Applets". Thanks Rao
Originally posted by Kavita Ghia: Hello friends, I am really keen to know in what way constructors are advantageous to use then the init() method.And if they are not advantageous then why do people use it.Anyone out there please reply as can't think of its usefullness.Maybe somewhere i am overlooking certain point. Regards, Kavita.