下面程序中,在主窗口单击鼠标后,就会生成一个新窗口。
import java.awt.*;
import java.awt.event.*;
public class java3 extends Frame
java3()
super("java3");
addNotify();
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
);
Insets insets=getInsets();
setSize(insets.left+insets.right+150,
insets.top+insets.bottom+150);
this.addMouseListener(MouseEventHandler());
class MouseEventHandler implements MouseAdapter
public void mousePresse(MouseEvent evt)
Rectangle bounds=getBounds();
int x=evt.getX()+bounds.x;
int y=evt.getY()+bounds.y;
java3 m=newjava3();
m.setLocation(x,y);
m.show();
static public void main(String[]args)
(new java3()).show();
参考答案:第1处:this.addMouseListener(new MouseEventHandler())
第2处:class MouseEventHandler extends MouseAdapter
第3处:public void mousePressed(MouseEvent evt)
解析: 第1处参数应为实例化对象;第2处继承父类应使用extends,implements实现的是接口;第3处单击鼠标后事件应为mousePressed。