/Users/lyon/j4p/src/classUtils/reflection/Command.java

1    package classUtils.reflection; 
2     
3    import classUtils.dumper.ClassFile; 
4    import gui.In; 
5     
6    /** 
7     * This class uses the command pattern to 
8     * implement a button. 
9     * 
10    * @author D. Lyon 
11    * @version 1.0 
12    */ 
13   public class Command 
14           implements 
15           java.awt.event.ActionListener, 
16           Runnable { 
17       private javax.swing.AbstractButton ab; 
18    
19       public Command(javax.swing.AbstractButton _ab) { 
20           ab = _ab; 
21           ab.addActionListener(this); 
22       } 
23    
24       public javax.swing.AbstractButton getButton() { 
25           return ab; 
26       } 
27    
28       public void actionPerformed(java.awt.event.ActionEvent e) { 
29           run(); 
30       } 
31    
32       public void run() { 
33       } 
34    
35       public static Class getClassFromFile() { 
36           ClassFile cf = null; 
37           try { 
38               cf = ClassFile.getClassFile(); 
39           } catch (Exception e) { 
40               return getClassFromFile(); 
41           } 
42           return getClass(cf.getClassName()); 
43       } 
44    
45       public static void promptUserForClassName() 
46               throws ClassNotFoundException, 
47               IllegalAccessException, 
48               InstantiationException { 
49           String cn = In.getString("enter a class name"); 
50           Class c = Class.forName(cn); 
51           In.message(c.newInstance().toString()); 
52       } 
53    
54       public static Class getClass(String className) { 
55           try { 
56               return Class.forName(className); 
57           } catch (ClassNotFoundException e) { 
58               In.message(e); 
59           } 
60           return null; 
61       } 
62    
63       public static void main(String[] args) { 
64           try { 
65               for (; ;) 
66                   promptUserForClassName(); 
67           } catch (ClassNotFoundException e) { 
68               e.printStackTrace(); 
69           } catch (IllegalAccessException e) { 
70               e.printStackTrace(); 
71           } catch (InstantiationException e) { 
72               e.printStackTrace(); 
73           } 
74       } 
75   }