欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

listenermanager.java

PIY(Program It Yourself)是一个基于Java的应用程序开发环境
JAVA
字号:
package piy;

import java.util.ArrayList;
import java.lang.reflect.*;

/**
* Handles the event listeners in the listeners package.  Give this class an object,
* and it will tell you the listener objects that can be added to the object.
* @author David Vivash
* @version 1.0, 12/02/01
*/
public class ListenerManager {

	private Class[] support = null;

	public ListenerManager(Class[] support) {
		this.support = support;
	}

	/**
	* Gets the event listeners that can be attached to the specified object.
	* @param o the object on which event listeners can be attached
	* @return an array of PiyEventListener representing all of the listeners that
	* can be attached
	*/
	public PiyEventListener[] getListeners(Object o) {
		Class type = null;
		ArrayList listeners = new ArrayList(4);

		Method getSupportedClass = null;

		try{
			for (int i=0; i<support.length; i++) {
				getSupportedClass = support[i].getMethod("getSupportedClass", null);

				type = (Class)getSupportedClass.invoke(null, null);
				if (type.isAssignableFrom(o.getClass())) listeners.add(support[i].newInstance());
			}
		} catch(Exception e) {
			System.out.println("Unable to instantiate listener class " + e.getMessage());
		}


		PiyEventListener[] toReturn = new PiyEventListener[listeners.size()];

		for (int i=0; i<toReturn.length; i++)
			toReturn[i] = (PiyEventListener)listeners.get(i);

		return toReturn;
	}

}

⌨️ 快捷键说明

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