我想知道如何在Java的Swing应用程序中添加时间延迟。我使用了Thread.sleep(time)
,也尝试了使用SwingWorker但是没有成功。以下是我的一部分代码:
switch (state) {
case 'A':
if (charAux == 'A') {
state = 'B';
//Here's where I'd like to add a time delay
jLabel13.setForeground(Color.red);
break;
} else {
//Here's where I'd like to add a time delay
jLabel12.setForeground(Color.red);
break;
}
}
我希望在使用SwingWorker时,您能够帮助我或解决我的疑问。