日期:2014-05-20  浏览次数:20600 次

实在搞不懂UI编程
import java.awt.*;
import java.awt.event.*;
public class Form extends WindowAdapter
{
  Frame f;
  
  public void display()
  {
  f = new Frame("Form");
  f.setSize(200,200);
  f.setLocation(200,140);
  f.setBackground(Color.lightGray);
   
  f.addWindowListener(new WinClose());
  f.setVisible(true);
  System.out.println("display is over");
  }
  
  public static void main(String[] args)
  {
  (new Form()).display();
  System.out.println("main is over"); //为什么main函数跑完了,程序没结束?
  }
}

class WinClose extends WindowAdapter
{
  public void windowClosing(WindowEvent e)
{
  System.exit(0);
  }
}
 

------解决方案--------------------
main方法执行完了,但你打开了个窗口,窗口没被关闭,程序自然没结束。