/Users/lyon/j4p/src/gui/run/examples/ColorPanel.java

1    package gui.run.examples; 
2     
3    import gui.ClosableJFrame; 
4    import gui.run.RunColorToggleButton; 
5    import gui.run.RunJob; 
6    import math.MathUtils; 
7     
8    import javax.swing.JPanel; 
9    import java.awt.Container; 
10   import java.awt.FlowLayout; 
11   import java.awt.Color; 
12    
13   public class ColorPanel extends JPanel { 
14       public static void main(String args[]) { 
15           class ColorFrame extends ClosableJFrame { 
16               ColorFrame() { 
17                   super("Colors!"); 
18                   Container c = getContentPane(); 
19                   c.setLayout(new FlowLayout()); 
20                   c.add(new ColorPanel()); 
21                   setSize(200, 200); 
22                   show(); 
23    
24               } 
25           } 
26           new ColorFrame(); 
27    
28    
29       } 
30    
31       RunJob job = new RunJob(1, true) { 
32           public void run() { 
33               Color randomColor = MathUtils.getRandomColor(); 
34               setBackground(randomColor); 
35               setForeground(randomColor); 
36           } 
37       }; 
38    
39       ColorPanel() { 
40           super(); 
41           setLayout(new FlowLayout()); 
42           add(new RunColorToggleButton("[ggo") { 
43               public void run() { 
44                   job.start(); 
45               } 
46           }); 
47           add(new RunColorToggleButton("[wstop") { 
48               public void run() { 
49                   job.stop(); 
50               } 
51           }); 
52       } 
53   }