因为做了个让程序只能运行一次登入界面,再次运行弹出对话框,因为对话框不点button,下面的语句就都被堵塞,现在我要让这个对话框动态提示在5秒内关闭,并且能在5秒自动后关闭.
就像QQ游戏大厅刚进入时的提示对话框那样自动关闭,各位大大帮帮吧?
谢谢了!

解决方案 »

  1.   

    dialog.setVisible(false); // 把对话框设置为不可见
    dialog.dispose(); // 释放对话框所占资源
      

  2.   

    算了,给你一段代码
    这是对话框类的import java.awt.Frame;import javax.swing.JDialog;
    import javax.swing.JPanel;
    import java.awt.*;
    import javax.swing.JButton;public class Dialog1 extends JDialog implements Runnable{
        JPanel panel1 = new JPanel();
        Thread t;
        int x;
        JButton jButton1 = new JButton();
        public Dialog1(Frame owner, String title, boolean modal) {
            super(owner, title, modal);
            try {
                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                jbInit();
                pack();
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }    public Dialog1() {
            this(new Frame(), "Dialog1", false);
        }    private void jbInit() throws Exception {
            panel1.setLayout(null);
            this.getContentPane().setLayout(null);
            this.getContentPane().add(panel1, null);
            panel1.add(jButton1, null);
            jButton1.setBounds(new Rectangle(119, 98, 129, 33));
            jButton1.setText("jButton1");
            panel1.setBounds(new Rectangle(10, 10, 383, 219));
            t=new Thread(this);
            t.start();
        }
        public void run()
        {
            for(x=5;x>0;x--)
            {
                jButton1.setText("退出(" + Integer.toString(x) + ")");
                try {
                    t.sleep(1000);
                } catch (Exception e) {
                    System.out.println("异常:" + e);
                }
            }
            this.dispose();
        }
    }