抛砖引玉,呵呵:import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.SwingConstants;import java.awt.Container;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.GridLayout;/**
 * @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;

Toolkit toolKit = this.getToolkit();
Dimension windowSize = toolKit.getScreenSize();
this.setBounds( 0,0,windowSize.width,windowSize.height );

Container c = this.getContentPane();
c.setLayout( new GridLayout( N,N ) );

for( int i = 0; i < N; i ++ ) {
for( int j = 0; j < N; j ++ ) {
ColorLabel label = new ColorLabel( time );
c.add( label );
}
}

setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
show();
} 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 );
}
}