Hi,
I have a game simulation program.
My main "Game" class starts up a simple GUI - a JPanel with a couple of buttons and a TextArea. The TextArea will be used to display status messages.
In addition to loading the GUI, the "Game" class creates several "Player" objects each running in their own
thread. I want each "player" object to be able to write to the TextArea when certain events occur.
The way I would choose to to this is to have the main 'Game' class publish a public "setStatusMessage(
String)" method. Then I would pass a reference to the Game object to each of the 'Player' objects, so that they could call (e.g.) game.setStatusMessage("my status message").
This all sounds very obvious, but in an application where there are long chains of created objects, does this mean that I will have to pass the reference to the gui object all the way down the chain ? Is there a better way to do this ? An established design
pattern that I could implement ?
Thanks in advance,
Tom