2.3.9 Nested Views Codehs | Confirmed — 2025 |

// 5. Text nested inside Content var bodyText = new Text("This text is inside a nested view."); bodyText.setColor("#333333"); bodyText.setPosition(content.getX() + 15, content.getY() + 30); bodyText.setFont("12pt Arial"); add(bodyText);

// 6. Another nested element: a simulated button (rectangle + text) var button = new Rectangle(100, 30); button.setColor("#4CAF50"); // Green button.setPosition(content.getX() + 15, content.getY() + 60); add(button); 2.3.9 nested views codehs

var contentView = new Rectangle(260, 300); contentView.setColor("white"); contentView.setBorderWidth(1); contentView.setPosition(parentView.getX() + 20, parentView.getY() + 80); add(contentView); Place a button or a text block inside contentView . var parentView = new Rectangle(300, 400); parentView

var parentView = new Rectangle(300, 400); parentView.setPosition(50, 50); // Position on the canvas parentView.setColor("lightgray"); parentView.setBorderWidth(2); add(parentView); Now, create a child that sits inside the parent. The key is that its x and y are relative to the parent’s position . If the parent is at (50, 50), and you want the child at the top-left corner of the parent, you set the child’s position to (50, 50) on the canvas, OR you set it relative to the parent. var parentView = new Rectangle(300