Core Java - [Applet: AWT Canvas Class]

♠ Posted by Unknown in at 06:29

Applet: AWT Canvas Class

//Create a Canvas that draws circle on itself. The circle color is given at creation time and size of the canvas.

package mj;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

Image: Java Canvas Exampleclass CanvasDemo extends Canvas
{
  public void paint(Graphics g)
  {
        g.setColor (Color.magenta);
        Dimension d=getSize();
        int z;
        int x=d.width/2;
        int y=d.height/2;
        int r=(int)((d.width < d.height)? 0.4*d.width:0.4*d.height);
        g.drawRect(0,0,d.width-1,d.height-1);
        g.fillOval(x-r,x-r,r,r);
    }
}

public class  CanvasApplet extends Applet
{
    public void init()
   {
        CanvasDemo can=new CanvasDemo();
        can.setSize(300,300);
        add(can);
    }
}



1 comments:

Nice topic thanks for posting
Unic Sol is the best Best java training in hyderabad with job placements. Along with java training full stack, mean stack, angular & testing tools training is provided by industry experts. We are the best java training in Hyderabad.

Post a Comment