Java program(applet) to draw concentric circle
Program:
import java.applet.*;
import java.awt.*;
import java.lang.*;
/*<applet code="code" height=800 width=700>
</applet> */
public class code extends Applet
{
public void init()
{
}
public void paint(Graphics g)
{
setBackground(Color.lightGray );
int rad=40; //radius of circle
int dia=rad*2; //diameter
for(int i=0;i<3;i++)
{
g.drawOval(300-(i*rad),300-(i*rad),50+(i*dia),50+(i*dia));
}
}
}
Output:-
Description:
to draw a circle in java applet we use a function
drawOval(int x,int y,int h,int w)
x,y are the coordinates
h height of oval
w is width of oval
to draw a circle h,w must be equal
Comments