Canvas Assignment Help

Assignment Help: >> Controls and Events - Canvas

Canvas:

A Canvas class gives the ability to construct generic GUI components.  A class does not have any default graphical representation, or any event handlers of its own. It inherits these capabilities from its super class Component. A Canvas class is commonly subclassed to construct customized GUI components consisting of drawing or images, and could handle user input events relating to mouse and keyboard actions. Its paint ( ) method is commonly overridden to render graphics in the component

// Illustrating Canvas

import java.awt.*;

import java.applet.*;

public class CanvasApplet extends Applet

{

public void init( )

{

DrawingRegion region = new DrawingRegion ( );

add(region);

}

}

class DrawingRegion extends Canvas

{

public DrawingRegion

{

setSize(150,150);

}

public void paint (Graphics g)

{

g.drawRect(0,0,149,149);     //draw border around region


g.drawstring("A 150 x 150 Canvas", 20,20);          //draw string

}

}

The given code draws a rectangular region on a canvas.

1359_Canvas.png

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd