Example usage for java.beans Beans getInstanceOf

List of usage examples for java.beans Beans getInstanceOf

Introduction

In this page you can find the example usage for java.beans Beans getInstanceOf.

Prototype

public static Object getInstanceOf(Object bean, Class<?> targetType) 

Source Link

Document

From a given bean, obtain an object representing a specified type view of that source object.

Usage

From source file:MainClass.java

public MainClass(String name) {
    super("Revived Beans!");
    try {//from  w w w .ja  va  2 s . c  om
        Object bean = Beans.instantiate(getClass().getClassLoader(), name);

        if (Beans.isInstanceOf(bean, JComponent.class)) {
            JComponent comp = (JComponent) Beans.getInstanceOf(bean, JComponent.class);
            getContentPane().add("Center", comp);
        } else {
            System.out.println("Bean is not a Component...");
        }
    } catch (java.io.IOException e1) {
        System.out.println("Error loading the serialized object");
    } catch (ClassNotFoundException e2) {
        System.out.println("Can't find the class that goes with the object");
    }
}