valdez.java

来自「jbshortcourse」· Java 代码 · 共 58 行

JAVA
58
字号
import java.awt.*;
import java.beans.*;
import java.io.*;
import java.lang.reflect.*;

public class Valdez {
  public static void main (String args[]) {
    TextField tf = new TextField ("Hello");
    inspect (tf);
  }

  public static void inspect (Object o) {
    inspect (o, System.out);
  }
  public static void inspect (Object o, OutputStream os) {
    inspect (o, new PrintWriter (os));
  }
  public static void inspect (Object o, Writer w) {
    inspect (o, new PrintWriter (w));
  }
  public static void inspect (Object o, PrintWriter pw) {
    try {
      Class c = o.getClass();
      BeanInfo bi = Introspector.getBeanInfo (c);
      EventSetDescriptor esd[] = bi.getEventSetDescriptors();
      PropertyDescriptor pd[] = bi.getPropertyDescriptors();
      Method readMethod;
      pw.println ("Bean Information for: " + c);
      for (int i=0;i<pd.length;i++) {
        if (i==0) pw.println ("\n\tProperties\n\t----------");
        pw.print ("(" + (i+1) + ")\t");
        pw.print (pd[i].getName() + " - " + pd[i].getPropertyType());
        readMethod = pd[i].getReadMethod();
        if (readMethod != null) {
          try {
            pw.println (" - " + readMethod.invoke (o, (Object[])null));
          } catch (IllegalArgumentException e) {
            pw.println ("Unable to inspect - Illegal Argument");
          } catch (IllegalAccessException e) {
            pw.println ("Unable to inspect - Illegal Access");
          } catch (InvocationTargetException e) {
            pw.println ("Unable to inspect - Invocation Problems");
          }
        } else {
          pw.println ();
        }
      }
      for (int i=0;i<esd.length;i++) {
        if (i==0) pw.println ("\n\tListeners\n\t---------");
        pw.print ("(" + (i+1) + ")\t");
        pw.println (esd[i].getName() + " - " + esd[i].getListenerType());
      }
    } catch (IntrospectionException e) {
      pw.println ("Introspection Error");
    }
    pw.flush();
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?