Apr 18, 2012

Canvas


A canvas is a component that has no default appearance or behavior. you can create canvas for custom drawing regions and work areas. It can receive input events from the mouse and the keyboard. You can use the setSize() method to make preferred size of the canvas.
         
          Canvas()

Example:
import java.awt.*;
import java.applet.*;
public class CanvasDemo extends Applet
{
public void init()
        {
              setLayout(new FlowLayout(FlowLayout.RIGHT));
              setBackground(Color.cyan);
              Canvas c=new Canvas();
              c.setBackground(Color.blue);
              c.setSize(100,50);
              add(c);
        }
}

/*
<applet code="CanvasDemo.class" width=150 height=75>
</applet>
*/

How to Execute this Example??

d:\>  javac CanvasDemo.java
d:\>  appletviewer CanvasDemo.java

Output:







0 comments :

Post a Comment