Interacting between child and parent components


Hi all! :slight_smile:

I’m pretty new with c++ programming and especially with the JUCE framework.

Everything went pretty smooth and intuitive until concepts such as virtual functions, listeners and all that interaction between classes came along, and I now I’m highly confused.

I’ll just describe my situation. In my project I made a class named “EventDraw”, inherited from the Component class, and contains a number of ShapeButton objects members. The class is inherited as well from the Button::Listener class, and thus able to respond to each of it’s ShapeButton objects.

Now I made another class inherited from Component named “SequencerDraw” as a parent Component of “EventDraw”. It’s role is to paint a number of "EventDraw"s components on the screen, according to the state of each “EventDraw” component - So basically I need “SequencerDraw” to be able to listen to each “EventDraw” component and react upon it.

I suppose it’s a fairly basic concept, but I wonder what’s the best way to achieve it. should I make a customised Listener for “EventDraw” and how? or should I make “SequencerDraw” listen to Button::Listener as well and receive messages from the buttons within each EventDraw?

I would truly appreciate if anyone would help me with this, and maybe even further with understanding what kind of relationship is necessary for one class to be able to listen to another class.

Thank you very much!


If your SequencerDraw class is instantiating the EventDraw objects then you could pass a reference to your SequencerDraw class to each of the EventDraw objects via their constructors and then the EventDraw instances could call a method in SequencerDraw to inform it when their state has changed so it can repaint.

Another way of achieving this is using the ChangeBroadcaster and ChangeListener JUCE classes to send a simple change message when the state of the EventDraw component changes.



I was thinking about this actually, but then I wasn’t sure if it’s the right way to do it… I would try it out, and look for these classes that you suggested.

Thank you very much Ed.