Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Refering variables of class which extends applet

 
Venkat Raman
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i have a code segment like the one below

Now how do I access value of variable varx(in an event handling class, for example)?
I have no instance of the class abcde!!!
Pl. help
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My $0.02:
If you define the event handling class as an anonymous class in say, init() you'd have access to the private variable.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or pass the variable into the listener constructor, eg:

Or write a "get" method and pass the Applet into the listener constructor, eg:

Or make the Applet its own listener, eg:

 
Venkat Raman
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Alicea and Carver. It really helped to sort out my code.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!