此jSlider代碼導致應用程序掛起。jSlider代碼導致應用程序掛起
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
for(int i=0;i<100;i++)
{
jSlider1.setValue(i);
Thread.sleep(3000);
}
} catch (InterruptedException ex) {
Logger.getLogger(AsdView.class.getName()).log(Level.SEVERE, null, ex);
}
}
感謝你們我更新了答案
Timer time = new Timer(100, new ActionListener() {
int percent = 0;
@Override
public void actionPerformed(ActionEvent e) {
percent++;
if (percent>100)
percent = 0;
jSlider1.setValue((int)(100*(percent/600.0)));
}
});
time.start();
拼寫爲「why」,而不是「y」。請不要在SO上使用l33t-sp34k。 – EboMike 2011-04-28 16:37:30
那麼你每循環迭代3秒鐘(共5分鐘!),你就睡3秒鐘。可能這就是爲什麼它掛着? – CoolBeans 2011-04-28 16:37:39
滑塊應該向右移動?像進度條? – ramya 2011-04-28 16:38:51