Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.awt.Component;
import java.awt.Container;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Component> findChildComponentsOfType(Component component, Class<?> type) {
        List<Component> foundComponents = new ArrayList<Component>();
        if (component instanceof Container) {
            Container container = (Container) component;
            for (Component child : container.getComponents()) {
                if (type.isAssignableFrom(child.getClass())) {
                    foundComponents.add(child);
                }
                foundComponents.addAll(findChildComponentsOfType(child, type));// recursive
            }
        }
        return foundComponents;
    }
}