how do you access a method of a class which extends JAppplet by another class??? you cannot create an object of it because there is no constructor... i got a class called Simulator and it has a protected method called sendMessage()... i want to access that method from another class within the same package...
When do you create a Simulator object? If it's from the JApplet object, you could make the constructor of the Simulator object take a JApplet (or the child class name) as a parameter. When you create the Simulator object from init() you can send "this" as the parameter.
Originally posted by Layne Lund: When you create the Simulator object from init() you can send "this" as the parameter.
Simulator is the class that has init()... is it possible to create Simulator object inside itself??? isn't it that it only happens in the main() of an application??? if Simulator is an application that's no problem but as an applet??? [ December 13, 2002: Message edited by: Benjoe Reyes ]
Joined: Dec 06, 2001
If Simulator is the function class that extends JApplet, then you can just call other class methods directly from its init(). It is rather simple really, or else I don't understand your question. Perhaps some code will help illustrate your problem more clearly.
Joined: Apr 24, 2002
layne, actually its only part of the problem... i started another topic about this... Elevator Simulator... basically how can a class ( use as an attribute of another class, but not nested) call a method of another class which is also an attribute of another different class
If you are talking about Applet to Applet communication and they are on the same HTML page, the you can use the getApplet() method to grab a reference to the other applet. If they are not on the same page, or one is not an Applet then you can create a static variable in the Applet to be called and have it save a copy of a reference to itself.
Now another class can have a reference to an instance to use the instance methods etc. MyApplet refToMyApplet = MyApplet.gotRef;
"JavaRanch, where the deer and the Certified play" - David O'Meara