Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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

import java.awt.event.KeyAdapter;

public class Main {
    public static void addKeyAdapterRecursively(final Container container, final KeyAdapter keyAdapter) {
        container.addKeyListener(keyAdapter);
        for (int i = 0; i < container.getComponentCount(); i++) {
            final Component child = container.getComponent(i);
            if (child instanceof Container) {
                addKeyAdapterRecursively((Container) child, keyAdapter);
            }
            child.addKeyListener(keyAdapter);
        }
    }
}