Jul 11, 2007

JAVA PROGRAM TO GENERATE CONECNTRIC CIRCLES:

In C++ to draw a circle on the screen, Radius of circle is used. But in Java to do the same task width of a circle and height of a circle is used. In C++ x and y coordinates are used for the center point of the circle but in JAVA x and y coordinates for top corner and left corner are used. So if we want to generate concentric circles in JAVA the following logic should be used.

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

/*

<applet code="appletdemo" height="400" width="500">

</applet>

*/



public class appletdemo extends Applet
{

public void paint(Graphics g)
{
try
{
for (int i=10;i<=100 ;i=i+10 )
{
g.drawOval(200-i/2,200-i/2,i,i);
Thread.sleep(100); // To generate a delay n miliseconds
}
}
catch(Exception e)
{
}
}
};
Technorati Tags :

No comments:

Post a Comment

Infolinks In Text Ads

Total Pageviews

Powered by Blogger.

Dont Forget To Follow Us

Blog Archive