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

1    package gui.run; 
2     
3     
4    public abstract class RunRadioButtonMenuItem extends 
5            javax.swing.JRadioButtonMenuItem implements 
6            java.awt.event.ActionListener, Runnable { 
7        public RunRadioButtonMenuItem(String label) { 
8            super(label); 
9            addActionListener(this); 
10       } 
11    
12       public RunRadioButtonMenuItem(String label, javax.swing.ButtonGroup bg) { 
13           super(label); 
14           bg.add(this); 
15           addActionListener(this); 
16           ShortcutUtils.addShortcut(this); 
17       } 
18    
19       public RunRadioButtonMenuItem( 
20               String label, 
21               javax.swing.ButtonGroup bg, 
22               javax.swing.JPopupMenu jpum) { 
23           super(label); 
24           bg.add(this); 
25           jpum.add(this); 
26           addActionListener(this); 
27           ShortcutUtils.addShortcut(this); 
28       } 
29    
30       public RunRadioButtonMenuItem(String l, javax.swing.Icon i) { 
31           super(l, i); 
32           addActionListener(this); 
33           ShortcutUtils.addShortcut(this); 
34       } 
35    
36       public RunRadioButtonMenuItem(javax.swing.Icon i) { 
37           super(i); 
38           addActionListener(this); 
39       } 
40    
41       public RunRadioButtonMenuItem() { 
42           addActionListener(this); 
43       } 
44    
45       public void actionPerformed(java.awt.event.ActionEvent e) { 
46           run(); 
47       } 
48    
49       public static void main(String args[]) { 
50           gui.ClosableJFrame cf = new gui.ClosableJFrame("RunRadioButtonMenuItem"); 
51           java.awt.Container c = cf.getContentPane(); 
52           javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup(); 
53    
54           javax.swing.JMenuBar mb = new javax.swing.JMenuBar(); 
55           RunMenu m = new RunMenu("[Scales"); 
56    
57           m.add(new RunRadioButtonMenuItem("[A harmonic Minor{ctrl shift A}", bg) { 
58               public void run() { 
59                   System.out.println(getText() + "=" + isSelected()); 
60               } 
61           }); 
62           m.add(new RunRadioButtonMenuItem("[Chromatic{ctrl shift C}", bg) { 
63               public void run() { 
64                   System.out.println(getText() + "=" + isSelected()); 
65               } 
66           } 
67           ); 
68    
69           mb.add(m); 
70           cf.setJMenuBar(mb); 
71           c.setLayout(new java.awt.FlowLayout()); 
72           cf.setSize(200, 200); 
73           cf.setVisible(true); 
74       } 
75    
76   }