| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 839 人关注过本帖
标题:关闭窗口问题
取消只看楼主 加入收藏
fighter19
Rank: 1
来 自:广东珠海
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-7-26
结帖率:100%
收藏
 问题点数:0 回复次数:0 
关闭窗口问题
下面的代码,本来没有实现关闭窗口的的,但我想实现,为什么加了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);
        }
    }
    
    
}
搜索更多相关主题的帖子: java 
2008-11-21 13:11
快速回复:关闭窗口问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026535 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved