/**
* @author yuch
*/
public class Play extends JFrame {
final static Color[] colors = { Color.black,Color.blue,Color.cyan,
Color.gray,Color.yellow,Color.green,
Color.magenta,Color.orange,Color.pink };
private int N = 10;
private long time = 1000;
public Play( int N,long time ) {
this.N = N;
this.time = time;
class ColorLabel extends JLabel implements Runnable {
private long time = 1000;
private Thread thread = null;
ColorLabel( long time ) {
this.time = time;
setOpaque( true );
setBorder( BorderFactory.createLineBorder(Color.red) );
thread = new Thread( this );
thread.start();
}
public void run() {
while( true ) {
int index = (int)(Math.random()*colors.length);
ColorLabel.this.setBackground( colors[index] );
try{
Thread.sleep( time );
}
catch( InterruptedException e ) {
}
}
}
}
public static void main(String[] args) {
new Play( 20,1000 );
}
}