先看代码
// 添加进度条
jDialog = new JDialog();
aJProgressBar = new JProgressBar(0, 100);
aJProgressBar.setStringPainted(true); // 显示百分比字符
aJProgressBar.setIndeterminate(false); // 不确定的进度条
jDialog.add(aJProgressBar);
jDialog.setVisible(false);
jDialog.setSize(300, 100);
// 出现后替他窗口不能点击
jDialog.setLocationRelativeTo(null);
// 使用进度条
new Thread() {
public void run() {
// 初始为没有查到结果,进度条用
hasChecked = false;
int value = 0;
while (!hasChecked) {
try {
if (value < aJProgressBar.getMaximum()) {
aJProgressBar.setValue(value++);
}
sleep(50);
} catch (Exception e) {
}
}
}
}.start();
new Thread() {
public void run() {
try {
// 函数调用流程:newRandomVip--newRandom
hasChecked = newRandomVip(jcb11.getSelectedItem()
.toString(), jcb12.getSelectedItem()
.toString(), jcb13.getSelectedItem()
.toString());
aJProgressBar.setValue(aJProgressBar.getMaximum());
sleep(100);
jDialog.setVisible(false);
} catch (Exception e) {
}
}
}.start();
jDialog.setModal(true);
jDialog.setVisible(true);
}
});
将进度条加到JDialog进行显示和关闭,