Topic: 这样写,为什么系统不能监听到窗口关闭事件呢?

  Print this page

1.这样写,为什么系统不能监听到窗口关闭事件呢? Copy to clipboard
Posted by: streetpoet
Posted on: 2004-03-17 09:08

import java.awt.*;
import java.awt.event.*;
public class Test
{
  public static void main(String args[])
  {
    display it=new display();
    it.displayit();
  }

}
class display extends WindowAdapter
{
  Frame f;
  void displayit()
  {
    f=new Frame("test");
    f.setSize(400,240);
    f.setLocation(0,0);
    f.addWindowListener(this);
    f.setVisible(true);
  }
    public void windowClosing()
  {
    System.exit(0);
  }

}

2.Re:这样写,为什么系统不能监听到窗口关闭事件呢? [Re: streetpoet] Copy to clipboard
Posted by: safe
Posted on: 2004-03-18 00:21

you should add the following code in class display

public void windowClosing(WindowEvent e) {
System.exit(0);
}


becasue in WindowAdapter source code, we can find

/**
* Invoked when a window is in the process of being closed.
* The close operation can be overridden at this point.
*/
public void windowClosing(WindowEvent e) {}

WindowAdapter do nothing for you

and your public void windowClosing() is an overloading method


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923