Javatpoint Logo
Javatpoint Logo

Java AWT Canvas

The Canvas class controls and represents a blank rectangular area where the application can draw or trap input events from the user. It inherits the Component class.

AWT Canvas class Declaration

Canvas Class Constructors

Sr. no. Constructor Description
1. Canvas() It constructs a new Canvas.
2. Canvas(GraphicConfiguration config) It constructs a new Canvas with the given Graphic Configuration object.

Class methods

Sr. no. Method name Description
1. void addNotify() It creates the canvas's peer.
2. void createBufferStrategy (int numBuffers) It creates a new multi buffering strategies on the particular component.
3. void createBufferStrategy (int numBuffers, BufferCapabilities caps) It creates a new multi buffering strategies on the particular component with the given buffer capabilities.
4. AccessibleContext getAccessibleContext() It gets the accessible context related to the Canvas.
5. BufferStrategy getBufferStrategy() It returns the buffer strategy used by the particular component.
6. void paint(Graphics g) It paints the canvas with given Graphics object.
7. void pdate(Graphics g) It updates the canvas with given Graphics object.

Method Inherited by Canvas Class

The Canvas has inherited above methods from the following classes:

  • lang.Component
  • lang.Object

Java AWT Canvas Example

In the following example, we are creating a Canvas in the Frame and painting a red colored oval inside it.

CanvasExample.java

Output:

java awt canvas
Next TopicJava AWT Scrollbar





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA