/Users/lyon/j4p/src/gui/run/RadioButtonTest.java

1    package gui.run; 
2     
3     
4    import gui.ClosableJFrame; 
5     
6    import javax.swing.ButtonGroup; 
7    import java.awt.Color; 
8    import java.awt.Container; 
9    import java.awt.FlowLayout; 
10    
11   public class RadioButtonTest extends ClosableJFrame { 
12    
13       Container c = getContentPane(); 
14       ButtonGroup bg = new ButtonGroup(); 
15    
16       public void addColorButton(RunRadio rr) { 
17           c.add(rr); 
18           bg.add(rr); 
19       } 
20    
21       public RadioButtonTest() { 
22           super("Using Button Groups"); 
23    
24           c.setLayout(new FlowLayout()); 
25           addColorButton(new RunRadio("[blue") { 
26               public void run() { 
27                   c.setBackground(Color.BLUE); 
28               } 
29           }); 
30           addColorButton(new RunRadio("[red") { 
31               public void run() { 
32                   c.setBackground(Color.RED); 
33               } 
34           }); 
35           addColorButton(new RunRadio("[cyan") { 
36               public void run() { 
37                   c.setBackground(Color.cyan); 
38               } 
39           }); 
40           addColorButton(new RunRadio("[yellow") { 
41               public void run() { 
42                   c.setBackground(Color.yellow); 
43               } 
44           }); 
45           addColorButton(new RunRadio("[green") { 
46               public void run() { 
47                   c.setBackground(Color.green); 
48               } 
49           }); 
50           c.setBackground(Color.white); 
51           setSize(250, 300); 
52           setVisible(true); 
53       } 
54    
55       public static void main(String args[]) { 
56           RadioButtonTest app = new RadioButtonTest(); 
57       } 
58    
59   }