当前位置: 代码迷 >> Java相关 >> 窗口关闭事件高手赐教,该如何解决
  详细解决方案

窗口关闭事件高手赐教,该如何解决

热度:1031   发布时间:2013-02-25 21:50:32.0
窗口关闭事件高手赐教
Java code
import java.awt.*;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class WindowColseing extends Frame {    Frame window;    public static void main(String[] args) {        WindowColseing c = new WindowColseing();        c.go();    }    public void go() {        window = new Frame("关闭窗口事件");        window.setBackground(Color.RED);        window.setSize(300, 300);        window.addWindowListener(new WindowAdapter() {            @Override            public void windowClosing(WindowEvent e) {                // TODO Auto-generated method stub                dispose();            }        });        window.setVisible(true);    }}

刚学JAVA事件, 不知是那里错了,就是不能关闭,高手赐教帮小弟看看那里错了..

------解决方案--------------------------------------------------------
package ycq.udplistener;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class NewJFrame extends Frame {
// Frame window;

public static void main(String[] args) {
NewJFrame c = new NewJFrame();
c.go();

}

public void go() {
// window = new Frame("关闭窗口事件");
setBackground(Color.RED);
setSize(300, 300);
addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
dispose();
}

});
setVisible(true);
}
}

  相关解决方案