Packages  This Package  Prev  Next  Index  

§1.3 Class Canvas

public  class  java.awt.Canvas
    extends  java.awt.Component  (II-§1.10)
{
        // Constructors
    public Canvas();	§1.3.1

        // Methods
    public void addNotify();	§1.3.2
    public void paint(Graphics  g);	§1.3.3
}
A Canvas component represents a blank rectangular area of the screen onto which the application can draw or from which the application can trap input events from the user.

An application must subclass the Canvas class in order to get useful functionality such as creating a custom component. The paint method (II-§1.3.3) must be overridden in order to perform custom graphics on the canvas.

The AWT sends the canvas all mouse, keyboard, and focus events that occur over it. The gotFocus (II-§1.10.21), lostFocus (II-§1.10.39), keyDown (II-§1.10.31) , keyUp (II-§1.10.32), mouseEnter (II-§1.10.43) , mouseExit (II-§1.10.44), mouseMove (II-§1.10.45), mouseDrag (II-§1.10.42), mouseDown (II-§1.10.41) , and mouseUp (II-§1.10.46) methods may be overridden in order to catch user events.


Constructors

Canvas

public Canvas()
Creates a canvas.

Methods

addNotify

public void addNotify()
This method calls the createCanvas method (II-§1.41.4) of the canvas's toolkit (II-§1.10.20) in order to create a CanvasPeer (II-§3.2) for this canvas. This peer allows the application to change the look of a canvas without changing its functionality.


Most applications do not call this method directly.
Overrides:
addNotify in class Component (II-§1.10.2).

paint

public void paint(Graphics g)
This method is called to repaint this canvas. Most applications that subclass Canvas should override this method in order to perform some useful operation.
The paint method provided by Canvas redraws this canvas's rectangle in the background color.
The graphics context's point is the top-left corner of this canvas. Its clipping region is the area of the context.
Parameters:
g - the graphics context
Overrides:
paint in class Component (II-§1.10.49).

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com