http://www.csdn.net/develop/read_article.asp?id=16454
看看我写的文档,另外,如下代码:
canvas,右键鼠标可以在区域里添加,选中一个canvas,然后按delete可以删除选中的对象import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.applet.*;public class applet6 extends Applet {
canvas curCom=null;
Image img1=null;
int width=0,height=0;
MediaTracker mt=new MediaTracker(this);
public void init() {
img1=this.getImage(this.getCodeBase(),"1.gif");//装载图片
this.setLayout(null);
mt.addImage(img1,0);
try {
  mt.waitForAll();
} catch(Exception ex) {System.err.println(ex.toString());}
width=img1.getWidth(this);
height=img1.getHeight(this);
this.addMouseListener(new MouseAdapter() {
  public void mouseClicked(MouseEvent e) {
    addcanvas(e);
  }
});
}public void addcanvas(MouseEvent e) {
if (e.getModifiers() == MouseEvent.BUTTON3_MASK) {
  canvas can = new canvas();
  this.add(can);
  can.setBounds(e.getX(), e.getY(), width, height);
  this.validate();
  curCom = can;
}
}public void removecanvas(KeyEvent e) {
this.remove(this.curCom);
this.validate();
this.repaint();
}class canvas extends Canvas {
public canvas() {
super();
this.addMouseListener(new MouseAdapter() {
  public void mouseClicked(MouseEvent e) {
    ((applet6)((canvas)e.getSource()).getParent()).curCom=(canvas)e.getSource();
  }
});
this.addKeyListener(new KeyAdapter() {
  public void keyPressed(KeyEvent e) {
    ((applet6)((canvas)e.getSource()).getParent()).removecanvas(e);
  }
});
}public void paint(Graphics g) {
g.drawImage(img1,0,0,this);
}
}
}