Sign in to follow this  

How should these class communicate?

This topic is 2542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a command pattern implemented and I need this command :

public class MakeStartNodeCommand implements ICommand{
private SquareNode _node;
public MakeStartNodeCommand(SquareNode node){
_node = node;
}
public void execute(){
_node.setNodeType(SquareNode.NodeType.START_NODE);
_node.getRectangle().setFillColor(Color.YELLOW);
//GridMap.repaint()
}
}



to communicate with this JPanel

public class GridMap extends javax.swing.JPanel{
//...stuff
}



specifically tell it to repaint its self. Any suggestion on a good way to achieve this? Usually I have a Controller class that
creates the only instance of main window and inside the main window I usually have a for example getJPanel() and gets for example the GridMap. And this is how others would communicate with the GridMap usually, but I am curious of other approaches, thats why I ask. Thanks.

Share this post


Link to post
Share on other sites
Pass the GridMap reference to the MakeStartNodeCommand constructor. Figuring out how to make this work may involve restructuring how you instantiate your objects, possibly including some factories to store the references until instantiation of the commands.

Share this post


Link to post
Share on other sites

This topic is 2542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this