Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.Component;

import java.lang.reflect.Method;

import javax.swing.JPanel;

public class Main {
    public static void roChildren(JPanel panel, Class<?>... classesToIgnore) {
        for (Component component : panel.getComponents()) {
            if (component instanceof JPanel) {
                roChildren((JPanel) component, classesToIgnore);
            } else {
                if (!ignoreClasses(component, classesToIgnore)) {
                    Method m = discover(component, "setEditable", boolean.class);
                    invoke(m, component, new Object[] { Boolean.FALSE });
                }
            }
        }
    }

    private static boolean ignoreClasses(Object o, Class<?>... classes) {
        if (classes != null) {
            for (Class<?> c : classes) {
                if (ignoreClass(o, c))
                    return true;
            }
        }
        return false;
    }

    public static Method discover(Object o, String method, Class<?> signature) {
        Method m = null;
        try {
            m = o.getClass().getMethod(method, signature);
        } catch (Exception ignore) {
        }
        return m;
    }

    public static void invoke(Method m, Object o, Object[] signature) {
        if (m == null)
            return;
        try {
            m.invoke(o, signature);
        } catch (Exception ignore) {
        }
    }

    private static boolean ignoreClass(Object o, Class<?> c) {
        return c.isAssignableFrom(o.getClass());
    }
}