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.awt.Container;

public class Main {
    static public void printAllComponents(Component root, int level) {
        if (root == null)
            return;

        printSpaceBeforeContent(level, root.getClass().getSimpleName());
        if (root instanceof Container) {
            Component[] components = ((Container) root).getComponents();
            if (components == null || components.length == 0) {
                return;
            }
            for (Component comp : components) {
                printAllComponents(comp, level + 1);
            }
        }
    }

    private static void printSpaceBeforeContent(int count, String content) {
        for (int i = 0; i < count; i++) {
            System.out.print(" ");
        }
        System.out.println(content);
    }
}