Extending Java's Canvas Class

The Canvas class, which is part of the java.awt package, makes an excellent base class for control beans. Creating a JavaBeans control from Java's Canvas class is simple. In this section, you write a bean that extends the Canvas class and can display any supported image file. Users type the name of the image file into the bean's property sheet, presented by the BeanBox or an application builder program, and the image file is loaded and displayed by the bean. In other words, this bean has an image filename property.

The code for the new bean class, named Picture, is in Listing 7.1. There are a couple of key elements in the Picture class code. All of the code used to load the image is in the getImageFilename() accessor ...

Get JavaBeans Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.