13.1. The Canvas Class

A Canvas is the simplest window and cannot contain any other GUI controls. Furthermore, you must place a canvas inside an existing window because a canvas cannot stand alone. As such, a Canvas does not have a layout manager. A canvas has two major roles:

  1. Drawing area. Suppose that you have a complicated GUI and want to create a custom graph or image. Rather than directly drawing into the underlying window, you may find it more convenient to insert a separate Canvas on which to perform the drawing. Note, however, that the Canvas should draw itself by overriding the paint method.

  2. Custom component. The Canvas is also the starting place for many custom components, for instance, an image label or image button.

Both approaches ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.