/Users/lyon/j4p/src/gui/ComMenuItem.java

1    package gui; 
2     
3    import java.awt.*; 
4    import java.lang.reflect.Method; 
5     
6    public class ComMenuItem extends MenuItem { 
7        public Method m; 
8        private BeanShortCutFrame bf; 
9        public String commandString; 
10    
11       ComMenuItem(String item) { 
12           super(item); 
13       } 
14    
15       public void invoke() { 
16           String targetParameters[] = null; 
17           try { 
18               m.invoke(bf, targetParameters); 
19           } catch (Exception ex) { 
20               System.out.println(ex); 
21           } 
22           ; 
23       } 
24    
25       public static ComMenuItem addMenuItem( 
26               Menu aMenu, 
27               String itemName, 
28               String _command, 
29               BeanShortCutFrame _bf) { 
30           ComMenuItem cmi = new ComMenuItem(itemName); 
31           cmi.bf = _bf; 
32           cmi.addActionListener(cmi.bf); 
33           aMenu.add(cmi); 
34           cmi.commandString = _command; 
35           return (cmi); 
36       } 
37    
38       public static String trimShortCutString(String s) { 
39           int i = s.indexOf(']'); 
40           if (i < 0) return s; 
41           return s.substring(i + 1, s.length()); 
42       } 
43    
44    
45   } 
46