// 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);

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.

// 3. Text nested inside Header var headerText = new Text("My App"); headerText.setColor("white"); headerText.setPosition(header.getX() + 15, header.getY() + 32); headerText.setFont("18pt Arial"); add(headerText);

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny