关闭窗口问题
下面的代码,本来没有实现关闭窗口的的,但我想实现,为什么加了addWindowListener(new WindowAdapter()的关闭窗口代码进去还是无法关闭的,请大家指教一下小弟,感激不尽~/*使用内部类处理鼠标移动事件和鼠标事件*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TowListenIner extends Frame implements ActionListener{
private Frame f;
private TextField tf;
public TowListenIner(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e){};
public static void main(String[] args){
TowListenIner that = new TowListenIner();
that.go();
}
public void go(){
f= new Frame("两个监听者的例子");
f.add("North",new Label("Click and drag the mouse"));
tf = new TextField(30);
f.add("South",tf);
f.addMouseMotionListener(new MouseMotionHandler());
f.addMouseListener(new MouseEventHandler());
f.setSize(300,300);
f.setVisible(true);
}
public class MouseMotionHandler extends MouseMotionAdapter{
public void mouseDragged(MouseEvent e){
String s = "鼠标的拖动位置:X="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
}
public class MouseEventHandler extends MouseAdapter{
public void mouseEntered(MouseEvent e){
String s = "鼠标进来";
tf.setText(s);
}
public void mouseExited(MouseEvent e){
String s= "鼠标离开";
tf.setText(s);
}
}
}