import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="shaps" width=300 height=400>
</applet>
*/
public class shaps extends Applet implements ActionListener
{
static int p=0;
Button cir,rec,ply,lin;
String msg;
public void init()
{
cir =new Button("Circle");
rec=new Button("Rectangle");
ply=new Button("Polygon");
lin=new Button("Line");
add(cir);
add(rec);
add(ply);
add(lin);
cir.addActionListener(this);
rec.addActionListener(this);
ply.addActionListener(this);
lin.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand()=="Circle")
p=1;
if(ae.getActionCommand()=="Rectangle")
p=2;
if(ae.getActionCommand()=="Polygon")
p=3;
if(ae.getActionCommand()=="Line")
p=4;
repaint();
}
public void paint(Graphics g)
{
g.setColor(Color.red);
switch(p)
{
case 1:
g.drawOval(100,100,200,200);
break;
case 2:
g.drawRect(100,100,200,200);
break;
case 3:
int a[]={400,200,950,190,45,234};
int b[]={500,300,250,190,50,234};
g.drawPolygon(a,b,6);
break;
case 4:
g.drawLine(0,0,100,100);
break;
}
}
}
OUTPUT:
0 comments:
Post a Comment