gpt4 book ai didi

java - 如何在 Java 中生成随机颜色?

转载 作者:搜寻专家 更新时间:2023-11-01 04:01:58 24 4
gpt4 key购买 nike

<分区>

我想在 Java 中为 JLabel 生成随机颜色。 JLabel 将每 100 毫秒更改一次背景,并且背景必须是随机的。如何做到这一点?

我想过使用 javax.swing.Timer 类来做到这一点。看,我被难住了。当我尝试 label.setBackground(Color.CYAN)

时,我什至没有得到背景
JLabel l=new JLabel("Label");
Timer t=new Timer(2,new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
// what is the code here?
}
});

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com