thanx for that ashish...just see if u can do something with this code
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class assignment1 extends Applet implements ItemListener
{
private Choice objects;
private DrawingCanvas drawing = new DrawingCanvas();
String msg="*";
public void init()
{
setLayout(new FlowLayout());
add(new Label("Choose an object: "));
objects = new Choice();
objects.add("Circle");
objects.add("Arrow");
objects.add("Square");
add(objects);
objects.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
boolean b;
msg+="before: inside itemChanged";
repaint();
b=drawing.handleChangeObject(objects.getSelectedItem());
msg+=b;
repaint();
}
public void paint(Graphics g){
g.drawString(msg,40,40);
}
}
class DrawingCanvas extends Canvas
{
String msg2="";
int xpts[]={10,30,20};
int ypts[]={100,100,115};
int num=3;
private int x = 8, y = 18;//circle
private int width = 30, height = 30;//circle
private int x1 = 18, y1 = 50;//arrow
private int width1 = 4, height1 = 50;//arrow
private Color myColor = Color.red;
private String object = "Circle";
public DrawingCanvas()
{
msg2+="Constructor instantiated";
setBackground(Color.green);
}
public void paint(Graphics g)
{
g.drawString(msg2,400,300);
if (object.equals("Circle"))
{
g.fillOval(x,y,width,height);
}
else if (object.equals("Arrow"))
{
g.drawPolygon(xpts,ypts,num);
g.drawRect(x,y,width,height);
}
else if (object.equals("Square"))
{
g.draw3DRect(40,50,10,10,true);
}
}
public boolean handleChangeObject(String s)
{
msg2+="INSIDE HANDLE CHANGE OBJECT";
object = s;
repaint();
return true;
}
}