I would like to generate a random color for JLabel
in Java. The JLabel
will be changing the background every 100 ms and the background has to be random. How to do this?
I thought of using javax.swing.Timer
class to do this. See, i am stumped.I am not even getting a background when i have tried the 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?
}
});