- Java code
import java.awt.*;import java.awt.event.*;public class TestWindowClose { public static void main (String[] args) { }}class MyFrame extends Frame{ MyFrame(String s){ super(s); setLayout(null); setBounds(300,300,400,300); this.setBackground(new Color(204,204,255)); setVisible(true); this.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ setVisible(false); System.exit(-1); } } ); }}
为什么运行没有界面,好像窗口直接就关闭了
------解决方案--------------------
main方法为空...
------解决方案--------------------
MyFrame构造函数里面写
setDefaultCloseOperation(this.EXIT_ON_CLOSE);
就可以在窗口关闭的时候关掉进程了吧
------解决方案--------------------
------解决方案--------------------
- Java code
import java.awt.*;import java.awt.event.*;public class TestWindowClose { public static void main (String[] args) { String s = null; MyFrame myFrame=new MyFrame(s); }}class MyFrame extends Frame{ MyFrame(String s){ super(s); setLayout(null); setBounds(300,300,400,300); this.setBackground(new Color(204,204,255)); setVisible(true); this.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ setVisible(false); System.exit(-1); } } ); }}