Swing:启用延迟按钮 [英] Swing: Enabling Buttons With Delay
本文介绍了Swing:启用延迟按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void OptionsActionPerformed(java.awt.event.ActionEvent evt)
{
// After clicking on button X, I want 4 other buttons to show up
// in a sequential order
ButtonTrue();
}
public void ButtonTrue()
{
Audio_Options.setVisible(true);
letsSleep();
Control_Options.setVisible(true);
letsSleep();
Display_Options.setVisible(true);
letsSleep();
Network_Options.setVisible(true);
}
public void letsSleep()
{
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
我有4个按钮。我希望它们按顺序出现,例如:
Button1 - 10秒 - Button2 - 10秒 - Button3 - 10秒 - 按钮4
I have 4 buttons. I want them to appear in a sequential order such as : Button1 - 10seconds - Button2 - 10 seconds - Button3 - 10seconds - Button 4
问题:每当我调用函数ButtonTrue(),它们在等待30秒后一起出现。可能导致此问题的原因是什么?
Problem: Whenever I call the function "ButtonTrue()", they all appear together after waiting 30 seconds. What can cause this problem to occur?
推荐答案
-
不要使用
Thread.sleep(int)
for Swing JComponent ,因为阻止了当前的EDTdon't use
Thread.sleep(int)
for Swing JComponent, because blocking current EDT你看过摇摆计时器
这篇关于Swing:启用延迟按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文