Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.*;
import java.util.ArrayList;

public class Main {
    public static void getComponentTreePosition(Component component, ArrayList position) {
        if (component.getParent() == null) {
            return;
        }
        getComponentTreePosition(component.getParent(), position);
        position.add(new Integer(component.getParent().getComponentCount() - getComponentIndex(component)));
    }

    public static final int getComponentIndex(Component component) {
        if (component != null && component.getParent() != null) {
            Container currentComponent = component.getParent();
            for (int index = 0; index < currentComponent.getComponentCount(); index++) {
                if (currentComponent.getComponent(index) == component)
                    return index;
            }
        }
        return -1;
    }
}