Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

accessing methods of an applet derivative

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Benjoe Reyes
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic