-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestColorPart.java
41 lines (41 loc) · 1.09 KB
/
TestColorPart.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.awt.Color;
import java.awt.GridLayout;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestColorPart extends JFrame {
JPanel jp1, jp2, jp3, jp4;
Color[] colors = { Color.BLACK, Color.RED, Color.GRAY, Color.GREEN, Color.BLUE, Color.WHITE };
public TestColorPart() {
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jp4 = new JPanel();
//Ñ»·
while(true){
Random r = new Random();
int len = colors.length;
//Í£¶Ù
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
jp1.setBackground(colors[r.nextInt(len)]);//Ë÷Òý
jp2.setBackground(colors[r.nextInt(len)]);//Ë÷Òý
jp3.setBackground(colors[r.nextInt(len)]);//Ë÷Òý
jp4.setBackground(colors[r.nextInt(len)]);//Ë÷Òý
this.setLayout(new GridLayout(2, 2));
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.setSize(400, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
public static void main(String[] args) {
new TestColorPart();
}
}