Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Pablo Pavon Mario.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Contributors:
 * Pablo Pavon Mario - initial API and implementation
 ******************************************************************************/

import java.awt.*;

import java.util.LinkedList;
import java.util.List;

public class Main {
    /**
     * Returns all the components (and their children) associated to the given container.
     *
     * @param container Container
     * @return {@code Component} list
     * @since 0.3.0
     */
    public static List<Component> getAllComponents(Container container) {
        List<Component> out = new LinkedList<Component>();
        for (Component comp : container.getComponents()) {
            out.add(comp);
            if (comp instanceof Container)
                out.addAll(getAllComponents((Container) comp));
        }

        return out;
    }
}