日期:2014-05-20 浏览次数:20788 次
import javax.swing.*; import java.awt.event.*; public class MainThreadTest { int time = 10; //mainThread 存活的时间(s) Timer timer = new Timer(time * 1000, new StopListener()); public MainThreadTest(){ timer.start(); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("结束程序"); new MainThreadTest(); try { Thread.sleep(1000000); System.out.println("测试输出"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private class StopListener implements ActionListener{ public void actionPerformed(ActionEvent e){ System.out.println("结束程序"); System.exit(0); } } }