读书人

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

发布时间: 2012-12-21 12:03:49 作者: rapoo

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);
}
});
}

读书人网 >编程

热点推荐