Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.awt.Canvas extends java.awt.Component { // Constructors public Canvas(); // Methods public void addNotify(); public void paint(Graphics g); }
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 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 , lostFocus , keyDown , keyUp , mouseEnter , mouseExit , mouseMove , mouseDrag , mouseDown , and mouseUp methods may be overridden in order to catch user events.
public Canvas()Creates a canvas.
public void addNotify()This method calls the createCanvas method of the canvas's toolkit in order to create a CanvasPeer 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 .
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 (0,0) point is the top-left corner of this canvas. Its clipping region is the area of the context.
Parameter Description g the graphics context Overrides:
paint in class Component .