posted 15 years ago
Hi Bill,
Welcome to JavaRanch!
Sounds like you're passing the window to the player, not the scorekeeper; otherwise in player you'd just use "myscorekeeper" or something, right?
But in any case, that's basically the right way to do things: either provide player with what it needs as constructor arguments, and let the player store a reference for its lifetime, or alternatively, make sure all the player methods that need a scorekeeper accept one as an argument, so that the caller has to provide the scorekeeper.
A third alternative -- and one that's strongly discouraged -- is to store things in public static variables, so that the player objects can just say, for example, MainWindow.theScoreKeeper to access that static variable. The problem with this is that your code becomes terribly messy, complex, interconnected and impossible to change after a while.