• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Secondary Frames

 
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beginner question here.
I've written a couple of different applets for web sites I do, and I've gotten the same little design problem with both - I want a frame to pop up that gets information from the user, that then modifies the variables in the main object (the one that extends Applet). And I'm left with the question, what's the best way to ensure my secondary frame has access to those variables. I do it one of two ways:
a) make it an inner class, so it has all the access it needs
b) make it a helper class, with a constructor that takes a reference to my main object (the one that extends Applet) as an argument.
Both of these seem to have their problems. When I have a bunch of these secondary frames, I feel like the main object gets cluttered. But I'm not used to seeing the second one done, so I would suspect there's some reason for that.
Is there a common solution to this? Is there something I should read that covers stuff like this?
Thanks
Eric
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a third way. Just because your Applet extends java.applet.APplet, doesn't prevent it from implementing an interface which you specify. I use interfaces a lot for this sort of work:

The above is obvoiusly not complete code, but it does illustrate the technique of passing around references to very specific interfaces, rather than the whole implementing class. This approach can easily be extended by adding extra methods to the interface, or implementing multiple small, specific interfaces.
 
Eric Barnhill
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahhhh, cool. Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic