时间不多,给你一点提示:
1、响应鼠标事件,选中的对象记入到Componet中。
2、响应键盘事件,当按中的健为"Delete",设置被选中的对象的visible=false;代码我没写,应该不麻烦。
1、响应鼠标事件,选中的对象记入到Componet中。
2、响应键盘事件,当按中的健为"Delete",设置被选中的对象的visible=false;代码我没写,应该不麻烦。
解决方案 »
- 向下转与覆盖的问题
- 关于jdk注册环境变量!
- 一个有关包和CLASSPATH的问题
- 菜鸟提问:什么是助手类?
- ~~~~谁知道jbuilderx 怎么让tab键=format???~~~~谁知道jbuilderx 怎么让tab键=format???~~~~
- 怎么把java.util.Date 转化成java.sql.Date
- 请问Comparable和Comparator 这两个类有什么区别在使用的时候
- 在linux下要做java程序,可不可以先在windows下做然后移植?
- 报考java程序员还是报考mcse?
- 請問一下在Applet中如何讀asop返回的頁面上的東西?
- 谁帮我解释解释?
- 请问那里有<<thinking in java>>的简体版电子书?
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);
}
}
}