This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes accessing methods of an applet derivative Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "accessing methods of an applet derivative" Watch "accessing methods of an applet derivative" New topic
Author

accessing methods of an applet derivative

Benjoe Reyes
Ranch Hand

Joined: Apr 24, 2002
Posts: 109
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...
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.


Java API Documentation
The Java Tutorial
Benjoe Reyes
Ranch Hand

Joined: Apr 24, 2002
Posts: 109
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 ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.
Benjoe Reyes
Ranch Hand

Joined: Apr 24, 2002
Posts: 109
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
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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
 
GeeCON Prague 2014
 
subject: accessing methods of an applet derivative