简体   繁体   English

插件加载时调用run()方法的工作方式是什么?

[英]How does it work that the method run() is called when the plugin is loaded?

In ImageJ , The Interface Plugin has a methods run() like this: 在ImageJ中,接口插件具有如下的run()方法:

package ij.plugin;

/** Plugins that acquire images or display windows should
    implement this interface. Plugins that process images 
    should implement the PlugInFilter interface. */
public interface PlugIn {

    /** This method is called when the plugin is loaded.
        'arg', which may be blank, is the argument specified
        for this plugin in IJ_Props.txt. */ 
    public void run(String arg);

}

why the run() method can be automatically called when the Plugin is loaded? 为什么在加载插件时可以自动调用run()方法?

the run() method can be automatically called when the Plugin is loaded? 插件加载时可以自动调用run()方法吗?

There is nothing automatic about it. 没有自动的东西。 There is a line of code in imagej library which says: imagej库中有一行代码,内容为:

thePlugIn.run(arg);

The full snippet is this (from here ): 完整的代码段是这样(从此处开始 ):

/** Runs the specified plugin and returns a reference to it. */
public static Object runPlugIn(String commandName, String className, String arg) {
    if (arg==null) arg = "";
    if (IJ.debugMode)
        IJ.log("runPlugIn: "+className+argument(arg));
    // Load using custom classloader if this is a user 
    // plugin and we are not running as an applet
    if (!className.startsWith("ij.") && applet==null)
        return runUserPlugIn(commandName, className, arg, false);
    Object thePlugIn=null;
    try {
        Class c = Class.forName(className);
        thePlugIn = c.newInstance();
        if (thePlugIn instanceof PlugIn)
            ((PlugIn)thePlugIn).run(arg);
        else
            new PlugInFilterRunner(thePlugIn, commandName, arg);
    }
    catch (ClassNotFoundException e) {
        if (IJ.getApplet()==null)
            log("Plugin or class not found: \"" + className + "\"\n(" + e+")");
    }
    catch (InstantiationException e) {log("Unable to load plugin (ins)");}
    catch (IllegalAccessException e) {log("Unable to load plugin, possibly \nbecause it is not public.");}
    redirectErrorMessages = false;
    return thePlugIn;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么从方法内部调用时方法回溯不起作用 - Why does method backtrack not work when called from within method 它是如何工作的,当我总是打开应用程序时,它会运行该方法,而不仅仅是当我点击运行时? - How does it work, that when I always open the app, it run the method and not only when I click on run? xhtml 中缺少属性会影响调用时的方法并且无法正常工作 - Missing property in xhtml affects method when called and does not work properlly Java run()方法如何工作? - How does Java run() method work? 扩展Thread类时如何调用run()方法 - How a run() method is called when we extend Thread class 当从扩展插件的类中调用时,为什么调用扩展活动的类不起作用? - Why calling a class that extends Activity does not work when called from one that extends Plugin? 从构造函数中调用时,关键字“ super”如何工作? - How does the keyword “super” work, when called from a constructor? 当调用 IntBinaryOperator 的新实例时,ApplyAsInt 如何自动工作? - How does ApplyAsInt work automatically when a new instance of IntBinaryOperator is called? 在未实现Observable的对象上调用Method时如何获得通知? - How to get Notified when Method is Called on Object that does not Implement Observable? JTextField setText()方法在run()方法中不起作用 - JTextField setText() method does not work in a run() method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM