Not sure if I fully understood the whole problem, so I will try and answer rather generically.
The Area and Ball classes can co-exist side-by-side. That's the most classical way to do that. In this case, the balls can know the area they belong to by adding a reference to the area.
Here is a possible way to do that:
Code:class Area
{
int width, height; color back;
// other stuff...
Ball[] balls;
Area() {} // Can have other parameters
Area(int ballNb) { createBalls(ballNb); }
void createBalls(int ballNb)
{
balls = new Ball[ballNb];
for (int i = 0; i < ballNb; i++)
{
ball[i] = new Ball(this);
}
}
}
class Ball
{
Area area;
int size;
Ball(Area a) { area = a; }
void display() { fill(area.back); ... }
}
BenHem's solution is nice too if the balls doesn't need to be known outside of the Area class, it has the advantage of hiding an "implementation detail". And the balls can access to all fields of the area they belong to, even the private ones!
And Ball class doesn't have to maintain an Area reference, as it is implicit as being the parent class.
Since you have a tentative implementation, perhaps you can show it (cut out stuff unneeded for the problem, if too long) so we can see where the problem is.