< prev index next >

src/com/sun/interview/wizard/Wizard.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


  97  *
  98  *    public class Demo extends Interview {
  99  *        public static void main(String[] args) {
 100  *          Demo d = new Demo();
 101  *          Wizard w = new Wizard(d);
 102  *          w.showInFrame(true);
 103  *        }
 104  *    }
 105  *</pre>
 106  */
 107 public class Wizard extends JComponent {
 108     /**
 109      * A minimal main program to invoke the wizard on a specified interview.
 110      * @param args Only one argument is accepted: the name of a class which is
 111      * a subtype of {@link Interview}.
 112      */
 113     public static void main(String[] args) {
 114         try {
 115             UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
 116 
 117             Class ic = (Class.forName(args[0], true, ClassLoader.getSystemClassLoader()));
 118             Interview i = (Interview)(ic.newInstance());
 119             Wizard w = new Wizard(i);
 120             w.showInFrame(true);
 121         }
 122         catch (Throwable e) {
 123             e.printStackTrace();
 124             System.exit(1);
 125         }
 126     }
 127 
 128     /**
 129      * Create a wizard to present an interview.
 130      * @param i The interview to be presented.
 131      */
 132     public Wizard(Interview i) {
 133         this(i, null);
 134     }
 135 
 136     /**
 137      * Create a wizard to present an interview.


 529 
 530     private void updateTitle(Window w) {
 531         String t;
 532         if (currFile == null
 533             || (defaultFile != null && currFile.equals(defaultFile)))
 534             t = title;
 535         else
 536             t = i18n.getString("wizard.titleAndFile", new Object[] {title, currFile.getPath()});
 537         if (w instanceof JFrame)
 538             ((JFrame) w).setTitle(t);
 539         else
 540             ((JDialog) w).setTitle(t);
 541     }
 542 
 543     /**
 544      * Invoke a performXXX method via reflection
 545      * @param s The name of the method to be invoked.
 546      */
 547     private void perform(String s) {
 548         try {
 549             Method m = Wizard.class.getDeclaredMethod(s, new Class[] { });
 550             m.invoke(Wizard.this, new Object[] { });
 551         }
 552         catch (IllegalAccessException ex) {
 553             System.err.println(s);
 554             ex.printStackTrace();
 555         }
 556         catch (InvocationTargetException ex) {
 557             System.err.println(s);
 558             ex.getTargetException().printStackTrace();
 559         }
 560         catch (NoSuchMethodException ex) {
 561             System.err.println(s);
 562         }
 563     }
 564 
 565     /**
 566      * Handle the "back" action
 567      */
 568     private void performBack() {
 569         try {




  97  *
  98  *    public class Demo extends Interview {
  99  *        public static void main(String[] args) {
 100  *          Demo d = new Demo();
 101  *          Wizard w = new Wizard(d);
 102  *          w.showInFrame(true);
 103  *        }
 104  *    }
 105  *</pre>
 106  */
 107 public class Wizard extends JComponent {
 108     /**
 109      * A minimal main program to invoke the wizard on a specified interview.
 110      * @param args Only one argument is accepted: the name of a class which is
 111      * a subtype of {@link Interview}.
 112      */
 113     public static void main(String[] args) {
 114         try {
 115             UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
 116 
 117             Class<?> ic = Class.forName(args[0], true, ClassLoader.getSystemClassLoader());
 118             Interview i = (Interview)(ic.newInstance());
 119             Wizard w = new Wizard(i);
 120             w.showInFrame(true);
 121         }
 122         catch (Throwable e) {
 123             e.printStackTrace();
 124             System.exit(1);
 125         }
 126     }
 127 
 128     /**
 129      * Create a wizard to present an interview.
 130      * @param i The interview to be presented.
 131      */
 132     public Wizard(Interview i) {
 133         this(i, null);
 134     }
 135 
 136     /**
 137      * Create a wizard to present an interview.


 529 
 530     private void updateTitle(Window w) {
 531         String t;
 532         if (currFile == null
 533             || (defaultFile != null && currFile.equals(defaultFile)))
 534             t = title;
 535         else
 536             t = i18n.getString("wizard.titleAndFile", new Object[] {title, currFile.getPath()});
 537         if (w instanceof JFrame)
 538             ((JFrame) w).setTitle(t);
 539         else
 540             ((JDialog) w).setTitle(t);
 541     }
 542 
 543     /**
 544      * Invoke a performXXX method via reflection
 545      * @param s The name of the method to be invoked.
 546      */
 547     private void perform(String s) {
 548         try {
 549             Method m = Wizard.class.getDeclaredMethod(s, new Class<?>[] { });
 550             m.invoke(Wizard.this, new Object[] { });
 551         }
 552         catch (IllegalAccessException ex) {
 553             System.err.println(s);
 554             ex.printStackTrace();
 555         }
 556         catch (InvocationTargetException ex) {
 557             System.err.println(s);
 558             ex.getTargetException().printStackTrace();
 559         }
 560         catch (NoSuchMethodException ex) {
 561             System.err.println(s);
 562         }
 563     }
 564 
 565     /**
 566      * Handle the "back" action
 567      */
 568     private void performBack() {
 569         try {


< prev index next >