调用以下函数来移动进度条,但我不知道为什么它不会移动,直到其他进程正常运行。
private void startProgressBar() {
signInProgressBar.setMinimum(0);
signInProgressBar.setMaximum(10);
Runnable r = new Runnable() {
@Override
public void run() {
int p = 1;
while(!loginCompleted) {
signInProgressBar.setValue(p);
//System.out.println(p);
p++;
try {Thread.sleep(5000);}catch(Exception exc) {}
}
}
};
new Thread(r,"progress_bar_thread").start();
}
调用的代码段startProgressBar
:
startProgressBar(); // CALL
String username = usernameTextField.getText();
String password = new String(passwordField.getPassword());
Openfire server = new Openfire();
boolean isConnected = server.connect(username,password);
if(isConnected) {
// Stash the username and password
User user = new User();
user.setUsername(username);
user.setPassword(password);
// Stop the progress bar
loginCompleted = true;
// Display the next window
UserGUI blab = new UserGUI();
blab.setVisible(true);
this.dispose(); // Dispose off the login window
}
可能是什么问题呢 ?