Hi everyone,
I just tried to learn the usage of "addChildComponent" & "removeChildComponent". The code is here:
class A : public Component
{
public:
A() {}
~A() {}
void paint (Graphics& g)
{
g.fillAll( Colours::black);
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (A)
};
class B : public Component
{
public:
B() {}
~B() {}
void paint (Graphics& g)
{
g.fillAll( Colours::pink);
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (B)
};
class MainContentComponent : public Component, public Timer
{
public:
MainContentComponent() : stamp(0)
{
setSize(800, 600);
a = new A;
addAndMakeVisible( a);
a->setBounds(0, 0, 800, 600);
startTimerHz(60);
}
~MainContentComponent()
{
removeChildComponent( b);
delete b;
}
void timerCallback() override
{
++stamp;
if( stamp >= 60)
{
removeChildComponent( a);
delete a;
b = new B;
addAndMakeVisible(b);
b->setBounds(0, 0, 800, 600);
}
repaint();
}
private:
int stamp;
A* a;
B* b;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};
Then a run-time error will happen. I can't understand why. can anybody help me ?
Thanks!
lgg
