java如何在单击按钮时自动洗牌背景色?
我试图在点击按钮时将背景色在一个帧上混洗。。为此,我已经使用了三次setBackground()
方法,但问题是。。它只显示第三种setBackground()
中指定的颜色,忽略前面两种setBackground()
颜色
if(s.equals("Click here")) {
this.setBackground(Color.yellow);
try
{
Thread.sleep(2000);
}
catch(InterruptedException ie)
{}
this.setBackground(Color.cyan);
try
{
Thread.sleep(2000);
}
catch (InterruptedException ie)
{ }
this.setBackground(Color.red);
}
帮我找出代码中的错误
# 1 楼答案
您还可以使用计时器: