timer = new javax.swing.Timer(8, createTextLoadAction());
timer.start();
public Action createTextLoadAction() {
return new AbstractAction("text load action") {
public void actionPerformed (ActionEvent e) {
if(jProgressBar1.getValue() < jProgressBar1.getMaximum()) {
jProgressBar1.setValue(jProgressBar1.getValue() +1);
tmp_CheckDb.getResultCheck(jProgressBar1.getValue());//你的程序
jLabel2.setText("目前已经检查:"+jProgressBar1.getValue()+"/"+jProgressBar1.getMaximum());
} else {
if(timer != null) {
timer.stop();
timer = null;
}
}
}
};
}
timer.start();
public Action createTextLoadAction() {
return new AbstractAction("text load action") {
public void actionPerformed (ActionEvent e) {
if(jProgressBar1.getValue() < jProgressBar1.getMaximum()) {
jProgressBar1.setValue(jProgressBar1.getValue() +1);
tmp_CheckDb.getResultCheck(jProgressBar1.getValue());//你的程序
jLabel2.setText("目前已经检查:"+jProgressBar1.getValue()+"/"+jProgressBar1.getMaximum());
} else {
if(timer != null) {
timer.stop();
timer = null;
}
}
}
};
}
解决方案 »
- getColumnName()怎么和getColumnLabel()一样?怎么才能得到字段名? java ResultSetMetaData
- 菜鸟的几个问题,绝对不难~~~
- 内部类的思考!求助
- 很有挑战的java IO 问题,如何实现byte[]转化为FileInputStream,不经过存储为文件
- 用Eclipse debug时, Scanner总是出错
- J2SE和J2EE有什么区别?
- 线程优先级的问题,如何理解如下程序的运行结果???
- 为何我的程序运行不了
- skyyoung再帮个忙,程序出错,谢谢!!
- 提问,关于能否在Canvas上面写文本
- 一个数值类型怎么转换成一个定长的字符串?
- java中有没有这样一个方法,就是当我的TEXTAREA的内容发生改变时触发一个事件
timer.start();
import java.awt.event.*;
import javax.swing.*;/** * 事件处理过程中UI的刷新 * @author Bruce * @version 1.0 */
public class TestUIUpdate2 {
public TestUIUpdate2() {
TestUIUpdate2Frame frame = new TestUIUpdate2Frame();
frame.pack();
frame.setVisible(true);
} public static void main(String[] args) {
new TestUIUpdate2();
}
}class TestUIUpdate2Frame
extends JFrame {
JTextPane pane = new JTextPane();
JButton button = new JButton("action...");
TestUIUpdate2Frame() {
init();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
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);
}
});
} private void init() {
pane.setPreferredSize(new Dimension(300, 200));
Container content = getContentPane();
content.setLayout(new BorderLayout());
content.add(pane, BorderLayout.CENTER);
content.add(button, BorderLayout.SOUTH);
}
}
它把按钮的action事件坐到一个线程里,然后用SwingUtilities.invokeLater调用
Thread t = new Thread(){
public void run(){
//我的耗时操作
}
};
t.start() ;很感谢ManFirst 和xxisxx, 但我觉得binny给我的链接很好,所以我把分说给他。祝大家圣诞快乐。