A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 谭荣强 高级黑马   /  2014-3-26 21:50  /  949 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

点关闭没反应,不知哪错了,帮忙看看那
import java.awt.*;
import java.awt.event.*;
class day2204
{
        public static void main(String[] args)
        {
        //Frame事件源
                Frame f = new Frame("my frame");//默认的布局 边界式               
                f.setSize(500,500);
                f.setLocation(50,40);
                f.setLayout(new FlowLayout());
                Button b = new Button("我d按钮");       
                f.add(b);
        //添加监听器 监听器里面放到是动作
                f.addWindowListener(new mywindow());
                f.setVisible(true);
        //System.out.println("Hello World!");
               
        }
}
class mywindow extends WindowAdapter
{
        public void windowsClosing(WindowEvent e)
        {
                System.out.println("关闭"+e.toString());
                System.exit(0);
        }
}

评分

参与人数 1技术分 +1 收起 理由
菜小徐 + 1

查看全部评分

3 个回复

倒序浏览
import java.awt.*;
import java.awt.event.*;
class Day2204
{
        public static void main(String[] args)
        {
        //Frame事件源
                Frame f = new Frame("my frame");//默认的布局 边界式               
                f.setSize(500,500);
                f.setLocation(50,40);
                f.setLayout(new FlowLayout());
                Button b = new Button("我d按钮");        
                f.add(b);
                //给按钮添加监视器
                b.addActionListener(new myButton());
        //添加监听器 监听器里面放到是动作
                f.addWindowListener(new mywindow());
                f.setVisible(true);
        //System.out.println("Hello World!");
               
        }
}
class mywindow extends WindowAdapter
{
        public void windowClosing(WindowEvent e)
        {
                System.out.println("关闭"+e.toString());
                System.exit(0);
        }
}
class myButton implements ActionListener
{
        public void actionPerformed(ActionEvent e)
        {
                System.out.println("关闭"+e.toString());
                System.exit(0);
        }
}
楼主代码基本都是对的 但就是在复写窗口监视器中的方法多写了一个s,你仔细看下windowClosing(WindowEvent e)方法就知道了,我又为楼主添加了通过点击按钮能关闭窗口的代码段

评分

参与人数 1技术分 +1 收起 理由
何伟超 + 1

查看全部评分

回复 使用道具 举报
看了半天不知道到底哪里错了...最后发现windowClosing方法多个s.....好神奇
回复 使用道具 举报
明白了  谢了。。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马