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

用代码关闭窗口
我想让窗口显示借秒后关闭,下面是我写的程序:
Java code

package lianxi;

import javax.swing.JDialog;
import java.awt.event.WindowEvent;
public class TestJDialog extends JDialog {

    
    public TestJDialog()
    {    
        
    }
    
    public static void main(String args[])
    {
        timeListener lis;
        TestJDialog tj= new TestJDialog();
        tj.setVisible(true);
        lis= new timeListener(tj);
        Thread thread= new Thread(lis);
        thread.start();    
    }
}

class timeListener implements Runnable{
    private TestJDialog testJDialog;
    public timeListener(TestJDialog testJDialog)
    {
        this.testJDialog=testJDialog;
    }
    
    public void run() {
        for(long i=0;i<10000;i++)//延时
        {
            System.out.println("i==="+i);
        }
        //问题:在此处添加代码,将testJDialog关闭,如何实现
        
    }
}



------解决方案--------------------
testJDialog.dispose();
------解决方案--------------------
System.exit(0);也行吧!