首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

实在搞不懂UI编程解决方案

2012-03-20 
实在搞不懂UI编程import java.awt.*import java.awt.event.*public class Form extends WindowAdapter{F

实在搞不懂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方法执行完了,但你打开了个窗口,窗口没被关闭,程序自然没结束。

热点排行