Class Canvas


@Bean(typeName="canvas") public class Canvas extends HtmlElementMixed
DTO for an HTML <canvas> element.

The canvas element provides a resolution-dependent bitmap canvas that can be used for rendering graphs, game graphics, or other visual images on the fly. It is used with JavaScript to create dynamic, scriptable rendering of 2D shapes and bitmap images. The canvas element requires both width and height attributes to define the canvas size, and the actual drawing is done through the Canvas API in JavaScript.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Basic canvas Canvas basic = canvas(300, 200); // Canvas with ID for JavaScript access Canvas withId = canvas(400, 300) .id("myCanvas"); // Canvas with styling Canvas styled = canvas(500, 400) .id("drawingCanvas") ._class("canvas-element") .style("border: 1px solid #ccc;"); // Canvas with event handlers Canvas interactive = canvas(800, 600) .id("gameCanvas") .onclick("handleCanvasClick(event)") .onmousemove("handleMouseMove(event)"); // Canvas with fallback content Canvas withFallback = canvas(600, 400) .id("chartCanvas") .children("Your browser does not support the canvas element."); // Canvas for data visualization Canvas chart = canvas(800, 500) .id("dataChart") .title("Interactive Data Chart"); // Canvas with accessibility Canvas accessible = canvas(400, 300) .id("accessibleCanvas") .title("Interactive drawing canvas") .children("Use your mouse to draw on this canvas.");

The following convenience methods are provided for constructing instances of this bean:

See Also: