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

Dialog显示后为何不执行下去?

请看下面的代码,Dialog被setVisible(true)后,println没有被执行,这是为什么?

import   java.awt.*;

class   t1
  {public   t1()
      {Frame   f=new   Frame( "test1 ");
        Dialog   d=new   Dialog(f,true);
        d.add(new   Button( "OK "), "Center ");
        d.pack();   d.setVisible(true);
        System.out.println( "why ");
      }
    public   static   void   main(String   args[])
      {new   t1();}  
  }


------解决方案--------------------
System.out.println( "why ");
放在 d.setVisible(true);
前面执行的时候会显示。你要是放在后面输入的时候他已经离开拉t1这个对象拉。所以不会在输入why