I am implementing a word guessing game. The attached image gives an idea of what I am doing. My GamePane
consists of two components, ControlPane
and HangManPane
, which is the top and bottom section of the attached image. when the player clicks, New Game
button, the GamePane
must be notified. subsequently, the GamePane
will request the SecretWord from ControlPane
and pass it on to HangManPane
to construct the model.
so two things happen here which I would like to know how to implement
ControlPane should fire notifications when the user clicks "New Game" button.so this fireChange should happen in the ActionListener of the
New Game
button.GamePane
listens to the notifications and pass the information toHangManPane
Using ChangeListener
would be appropriate. I did my part of searching, but unable to grasp on how to implement here. Any suggestions are kindly welcome
public class GamePane extends JPanel {
public GamePane(){
ControlPane cp = new ControlPane();
//if user clicks New Game on ControlPane, notify me
//I will then do the following
HangManModel model = new DefaultHangManModel(cp.getSecretWord());
HangManPane hangManPane = new HangManPane(model);
setLayout(new GridLayout(0,1));
this.add(cp);
this.add(pane);
}
}