Adding a Canvas

  1. Click on the Canvas component in the AWT palette tab.
  2. Click in the cell where you want to place the drawing canvas.
  3. Open the attribute editor by clicking on its button in the main toolbar.
  4. Type a unique component ID in the name box.
The Canvas component is a subclass, VJCanvas, of the AWT Canvas class. You can draw objects in it programmatically. It generates VJCanvas.PAINT_EVENT and VJCanvas.UPDATE_EVENT events when paint and update are called.

To paint on the canvas, you need to respond to the PAINT_EVENT, which is generated from a canvas when paint is called.

To respond, add code to the handleEvent() function of the object containing the canvas or to the handleEvent() function contained in your project group file (project-name.java).

For example, if you have a canvas component called canvas1, you can add paint behavior to the group file by entering the following code:

  public boolean handleEvent(Message msg, Event evt) {
    switch (evt.id) {
    	case PAINT_EVENT:
    	  if (msg.target == gui.canvas1) {
    	      // create canvas object and graphics object
              VJCanvas vjcanvas = (VJCanvas)gui.canvas1.getBody();
              Graphics g = vjcanvas.getGrahpics();
              // call your paint function here
    	  }
    }
    return super.handleEvent(msg, evt);
  }

Special Attributes

minHeight Minimum height (in pixels) of the canvas.
minWidth Minimum width (in pixels) of the canvas.

See also:

Generating Java Source Code
Adding Operations to Components
Laying Out the Interface
Visual Java GUI Builder Palette

Visual Java GUI Builder API Documentation
Visual Java GUI Builder Runtime Packages
Class Hierarchy
Index of All Fields and Methods