moduleclasscontainer.java

来自「Petri网分析工具PIPE is open-source」· Java 代码 · 共 62 行

JAVA
62
字号
package pipe.gui;import java.lang.reflect.Constructor;import java.lang.reflect.Method;/** * ModuleClass encapsulates information about the Module class and is designed to be used as a userobject in nodes in a JTree, in this case for nodes representing module classes. This isn't designed for use anywhere else. * @author Camilla Clifford */public class ModuleClassContainer{  private String displayName;  private Method methods[];  private Class thisClass;  /** Sets up the private fields, includes instantiating an object and calling the getName method used to set the displayName.   * @param cl The class that the ModuleClass encapsulates.   */  public ModuleClassContainer(Class cl)  {    thisClass = cl;    try    {      Constructor ct = thisClass.getDeclaredConstructor(null);      Object moduleObj = ct.newInstance(null);      // invoke the name method for display      Method meth = thisClass.getMethod("getName", null);      displayName = (String)meth.invoke(moduleObj, null);    }    catch (Throwable e)    {      System.out.println("Error in ModuleClass instantiation: " + e.toString());    }  }  /** Overides the object method in order to provide the correct display name */  public String toString()  {    return displayName;  }  /** Returns the class object that the ModuleClass encapsulates */  public Class returnClass()  {    return thisClass;  }}

⌨️ 快捷键说明

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