黑马程序员技术交流社区
标题:
监视器问题,点关闭的时候没反应
[打印本页]
作者:
谭荣强
时间:
2014-3-26 21:50
标题:
监视器问题,点关闭的时候没反应
点关闭没反应,不知哪错了,帮忙看看那
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);
}
}
作者:
caijunsong
时间:
2014-3-26 23:23
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)方法就知道了,我又为楼主添加了通过点击按钮能关闭窗口的代码段
作者:
宋超2356
时间:
2014-3-26 23:30
看了半天不知道到底哪里错了...最后发现windowClosing方法多个s.....好神奇
作者:
谭荣强
时间:
2014-3-27 13:03
明白了 谢了。。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2