2.3.9 Nested Views Codehs -
// Header child view (inside parent) var headerView = new Rectangle(260, 50); headerView.setColor("navy"); headerView.setPosition(parentView.getX() + 20, parentView.getY() + 20); add(headerView); This is the "nested" part. The text should sit inside the header view. Again, we calculate its position based on the header’s position.
Wait, careful: In most Canvas-based libraries, add(child) adds to absolute coordinates. To simulate nesting, we manually offset. 2.3.9 nested views codehs
By following the step-by-step code above—creating a parent, adding children with relative offsets, and nesting text inside those children—you will not only pass 2.3.9 but also build a strong foundation for future projects like building calculators, to-do lists, or even small games on CodeHS. // Header child view (inside parent) var headerView
Child position = Parent position + Offset. headerView.setPosition(parentView.getX() + 20

