// B8. Write an applet to draw n squares, rectangle and circles.
/* <applet code="B8" height=1000 width=1000> </applet> */
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class B8 extends Applet implements ActionListener
{
TextField text1,text2;
public void init()
{
setLayout(null);
text1= new TextField(20);
text1.setBounds(150,50,40,20);
add(text1);
text1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
int n;
String str;
int x=200,y=200,w=400;
int x1=200,y1=200,w1=300;
int x2=160,y2=160,w2=200,z2=300 ;
g.drawString("Input value for n:",50,60);
str=text1.getText();
n=Integer.parseInt(str);
for(int i=0;i<n;i++)
{
g.setColor(Color.red);
g.drawOval(x,y,w,w);
x=x-10;
y=y-10;
w=w+20;
}
for(int i=0;i<n;i++)
{
g.setColor(Color.blue);
g.drawRect(x1,y1,w1,w1);
x1=x1-10;
y1=y1-10;
w1=w1+20;
}
for(int i=0;i<n;i++)
{
g.setColor(Color.green);
g.drawRect(x2,y2,w2,z2);
x2=x2-20;
y2=y2-30;
w2=w2+40;
z2=z2+50;
}
}
}
No comments :
Post a Comment