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

swing 长时间任务的实施提示在界面的同步提示

2012-12-21 
swing 长时间任务的执行提示在界面的同步提示摘抄精要的函数:程序是片段摘抄,括号关系不一定对,关键是思路

swing 长时间任务的执行提示在界面的同步提示
摘抄精要的函数:
程序是片段摘抄,括号关系不一定对,关键是思路,重点在button事件中启动线程。
btn_sync2local.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         //-----------------------------
         new Thread() {
    public void run() {
                 downloadDirtyFiles();
    }
         }.start();
         //-----------------------------
    }
});




button.addActionListener(new   ActionListener()   {
public   void   actionPerformed(ActionEvent   e)   {
   new   Thread()   {
    public   void   run()   {
       try   {
          showMessage( "step   one... ");
          Thread.sleep(3000);
          showMessage( "\nstep   two... ");
          Thread.sleep(3000);
          showMessage( "\nfinished. ");
          Thread.sleep(3000);
         }
          catch   (InterruptedException   ie)   {
             //ignored
      }
    }
    }.start();
}
});


private   void   showMessage   (final   String   msg)   {
        SwingUtilities.invokeLater(new   Runnable()   {
            public   void   run()   {
                pane.setText(pane.getText()   +   msg);
            }
        });
    }

热点排行